blob: f3960c5ebf313ec8ac89865c05482a0ca4057332 [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 Shmidt6c0da2b2015-01-05 13:08:17 -080079void 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 Shmidtc55524a2011-07-07 11:18:38 -070083 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084 * drop to 11b if driver does not support 11g */
85
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070086#ifdef CONFIG_IEEE80211N
87 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080088 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
89 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070090 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080091 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070092 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080093 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070094 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -070095 int i, no_ht = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080096 for (i = 0; i < wpa_s->hw.num_modes; i++) {
97 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
98 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070099 break;
100 }
101 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700102
103#ifdef CONFIG_HT_OVERRIDES
104 if (ssid->disable_ht) {
105 conf->ieee80211n = 0;
106 conf->ht_capab = 0;
107 no_ht = 1;
108 }
109#endif /* CONFIG_HT_OVERRIDES */
110
111 if (!no_ht && mode && mode->ht_capab) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700112 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700113#ifdef CONFIG_P2P
114 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
115 (mode->ht_capab &
116 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
117 ssid->ht40)
118 conf->secondary_channel =
119 wpas_p2p_get_ht40_mode(wpa_s, mode,
120 conf->channel);
121 if (conf->secondary_channel)
122 conf->ht_capab |=
123 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
124#endif /* CONFIG_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800125
126 /*
127 * white-list capabilities that won't cause issues
128 * to connecting stations, while leaving the current
129 * capabilities intact (currently disabled SMPS).
130 */
131 conf->ht_capab |= mode->ht_capab &
132 (HT_CAP_INFO_GREEN_FIELD |
133 HT_CAP_INFO_SHORT_GI20MHZ |
134 HT_CAP_INFO_SHORT_GI40MHZ |
135 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800136 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800137 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700138
139 if (mode->vht_capab && ssid->vht) {
140 conf->ieee80211ac = 1;
141 wpas_conf_ap_vht(wpa_s, conf, mode);
142 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800143 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700144 }
145#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800146}
147
148
149static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
150 struct wpa_ssid *ssid,
151 struct hostapd_config *conf)
152{
153 struct hostapd_bss_config *bss = conf->bss[0];
154
155 conf->driver = wpa_s->driver;
156
157 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
158
159 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
160 &conf->channel);
161 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
162 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
163 ssid->frequency);
164 return -1;
165 }
166
167 wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700168
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800169 if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
170 conf->ieee80211h = 1;
171 conf->ieee80211d = 1;
172 conf->country[0] = wpa_s->conf->country[0];
173 conf->country[1] = wpa_s->conf->country[1];
174 }
175
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700176#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700177 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
178 (ssid->mode == WPAS_MODE_P2P_GO ||
179 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 /* Remove 802.11b rates from supported and basic rate sets */
181 int *list = os_malloc(4 * sizeof(int));
182 if (list) {
183 list[0] = 60;
184 list[1] = 120;
185 list[2] = 240;
186 list[3] = -1;
187 }
188 conf->basic_rates = list;
189
190 list = os_malloc(9 * sizeof(int));
191 if (list) {
192 list[0] = 60;
193 list[1] = 90;
194 list[2] = 120;
195 list[3] = 180;
196 list[4] = 240;
197 list[5] = 360;
198 list[6] = 480;
199 list[7] = 540;
200 list[8] = -1;
201 }
202 conf->supported_rates = list;
203 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800204
205 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700206 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800207
208 if (ssid->p2p_group) {
209 os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
210 os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
211 4);
212 os_memcpy(bss->ip_addr_start,
213 wpa_s->parent->conf->ip_addr_start, 4);
214 os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
215 4);
216 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217#endif /* CONFIG_P2P */
218
219 if (ssid->ssid_len == 0) {
220 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
221 return -1;
222 }
223 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 bss->ssid.ssid_len = ssid->ssid_len;
225 bss->ssid.ssid_set = 1;
226
Dmitry Shmidt04949592012-07-19 12:16:46 -0700227 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
228
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800229 if (ssid->auth_alg)
230 bss->auth_algs = ssid->auth_alg;
231
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
233 bss->wpa = ssid->proto;
234 bss->wpa_key_mgmt = ssid->key_mgmt;
235 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800236 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800237 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
239 if (bss->ssid.wpa_psk == NULL)
240 return -1;
241 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
242 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800243 } else if (ssid->passphrase) {
244 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800245 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
246 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
247 struct hostapd_wep_keys *wep = &bss->ssid.wep;
248 int i;
249 for (i = 0; i < NUM_WEP_KEYS; i++) {
250 if (ssid->wep_key_len[i] == 0)
251 continue;
252 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
253 if (wep->key[i] == NULL)
254 return -1;
255 os_memcpy(wep->key[i], ssid->wep_key[i],
256 ssid->wep_key_len[i]);
257 wep->len[i] = ssid->wep_key_len[i];
258 }
259 wep->idx = ssid->wep_tx_keyidx;
260 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261 }
262
Dmitry Shmidt04949592012-07-19 12:16:46 -0700263 if (ssid->ap_max_inactivity)
264 bss->ap_max_inactivity = ssid->ap_max_inactivity;
265
266 if (ssid->dtim_period)
267 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800268 else if (wpa_s->conf->dtim_period)
269 bss->dtim_period = wpa_s->conf->dtim_period;
270
271 if (ssid->beacon_int)
272 conf->beacon_int = ssid->beacon_int;
273 else if (wpa_s->conf->beacon_int)
274 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700275
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800276#ifdef CONFIG_P2P
277 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
278 wpa_printf(MSG_INFO,
279 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
280 wpa_s->conf->p2p_go_ctwindow, conf->beacon_int);
281 conf->p2p_go_ctwindow = 0;
282 } else {
283 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
284 }
285#endif /* CONFIG_P2P */
286
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800287 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
288 bss->rsn_pairwise = bss->wpa_pairwise;
289 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
290 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291
292 if (bss->wpa && bss->ieee802_1x)
293 bss->ssid.security_policy = SECURITY_WPA;
294 else if (bss->wpa)
295 bss->ssid.security_policy = SECURITY_WPA_PSK;
296 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800297 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
299 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800300 if (bss->default_wep_key_len)
301 cipher = bss->default_wep_key_len >= 13 ?
302 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
303 bss->wpa_group = cipher;
304 bss->wpa_pairwise = cipher;
305 bss->rsn_pairwise = cipher;
306 } else if (bss->ssid.wep.keys_set) {
307 int cipher = WPA_CIPHER_WEP40;
308 if (bss->ssid.wep.len[0] >= 13)
309 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800311 bss->wpa_group = cipher;
312 bss->wpa_pairwise = cipher;
313 bss->rsn_pairwise = cipher;
314 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800316 bss->wpa_group = WPA_CIPHER_NONE;
317 bss->wpa_pairwise = WPA_CIPHER_NONE;
318 bss->rsn_pairwise = WPA_CIPHER_NONE;
319 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700321 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
322 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800323 bss->wpa_group == WPA_CIPHER_GCMP ||
324 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
325 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700326 /*
327 * Strong ciphers do not need frequent rekeying, so increase
328 * the default GTK rekeying period to 24 hours.
329 */
330 bss->wpa_group_rekey = 86400;
331 }
332
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700333#ifdef CONFIG_IEEE80211W
334 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
335 bss->ieee80211w = ssid->ieee80211w;
336#endif /* CONFIG_IEEE80211W */
337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338#ifdef CONFIG_WPS
339 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800340 * Enable WPS by default for open and WPA/WPA2-Personal network, but
341 * require user interaction to actually use it. Only the internal
342 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700343 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800344 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
345 bss->ssid.security_policy != SECURITY_PLAINTEXT)
346 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800347 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800348 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
349 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800350 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
351 * configuration */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700353
354 if (!ssid->ignore_broadcast_ssid)
355 bss->wps_state = 2;
356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 bss->ap_setup_locked = 2;
358 if (wpa_s->conf->config_methods)
359 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
360 os_memcpy(bss->device_type, wpa_s->conf->device_type,
361 WPS_DEV_TYPE_LEN);
362 if (wpa_s->conf->device_name) {
363 bss->device_name = os_strdup(wpa_s->conf->device_name);
364 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
365 }
366 if (wpa_s->conf->manufacturer)
367 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
368 if (wpa_s->conf->model_name)
369 bss->model_name = os_strdup(wpa_s->conf->model_name);
370 if (wpa_s->conf->model_number)
371 bss->model_number = os_strdup(wpa_s->conf->model_number);
372 if (wpa_s->conf->serial_number)
373 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
374 if (is_nil_uuid(wpa_s->conf->uuid))
375 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
376 else
377 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
378 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700379 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800380no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381#endif /* CONFIG_WPS */
382
383 if (wpa_s->max_stations &&
384 wpa_s->max_stations < wpa_s->conf->max_num_sta)
385 bss->max_num_sta = wpa_s->max_stations;
386 else
387 bss->max_num_sta = wpa_s->conf->max_num_sta;
388
389 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
390
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700391 if (wpa_s->conf->ap_vendor_elements) {
392 bss->vendor_elements =
393 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
394 }
395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 return 0;
397}
398
399
400static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
401{
402#ifdef CONFIG_P2P
403 struct wpa_supplicant *wpa_s = ctx;
404 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405
406 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700407 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800409 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
410 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
412 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700413 buf + IEEE80211_HDRLEN + 1,
414 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415#endif /* CONFIG_P2P */
416}
417
418
419static void ap_wps_event_cb(void *ctx, enum wps_event event,
420 union wps_event_data *data)
421{
422#ifdef CONFIG_P2P
423 struct wpa_supplicant *wpa_s = ctx;
424
Jouni Malinen75ecf522011-06-27 15:19:46 -0700425 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 struct wps_event_fail *fail = &data->fail;
427
Jouni Malinen75ecf522011-06-27 15:19:46 -0700428 if (wpa_s->parent && wpa_s->parent != wpa_s &&
429 wpa_s == wpa_s->global->p2p_group_formation) {
430 /*
431 * src/ap/wps_hostapd.c has already sent this on the
432 * main interface, so only send on the parent interface
433 * here if needed.
434 */
435 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
436 "msg=%d config_error=%d",
437 fail->msg, fail->config_error);
438 }
439 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 }
441#endif /* CONFIG_P2P */
442}
443
444
445static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800446 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800448 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449}
450
451
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700452#ifdef CONFIG_P2P
453static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
454 const u8 *psk, size_t psk_len)
455{
456
457 struct wpa_supplicant *wpa_s = ctx;
458 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
459 return;
460 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
461}
462#endif /* CONFIG_P2P */
463
464
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
466{
467#ifdef CONFIG_P2P
468 struct wpa_supplicant *wpa_s = ctx;
469 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470
471 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700472 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 return -1;
474 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
475 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700476 buf + IEEE80211_HDRLEN + 1,
477 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478#endif /* CONFIG_P2P */
479 return 0;
480}
481
482
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800483static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700484 const u8 *bssid, const u8 *ie, size_t ie_len,
485 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700488 unsigned int freq = 0;
489
490 if (wpa_s->ap_iface)
491 freq = wpa_s->ap_iface->freq;
492
Dmitry Shmidt04949592012-07-19 12:16:46 -0700493 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700494 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495}
496
497
498static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
499 const u8 *uuid_e)
500{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 struct wpa_supplicant *wpa_s = ctx;
502 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503}
504
505
506static void wpas_ap_configured_cb(void *ctx)
507{
508 struct wpa_supplicant *wpa_s = ctx;
509
510 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
511
512 if (wpa_s->ap_configured_cb)
513 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
514 wpa_s->ap_configured_cb_data);
515}
516
517
518int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
519 struct wpa_ssid *ssid)
520{
521 struct wpa_driver_associate_params params;
522 struct hostapd_iface *hapd_iface;
523 struct hostapd_config *conf;
524 size_t i;
525
526 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
527 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
528 return -1;
529 }
530
531 wpa_supplicant_ap_deinit(wpa_s);
532
533 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
534 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
535
536 os_memset(&params, 0, sizeof(params));
537 params.ssid = ssid->ssid;
538 params.ssid_len = ssid->ssid_len;
539 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540 case WPAS_MODE_AP:
541 case WPAS_MODE_P2P_GO:
542 case WPAS_MODE_P2P_GROUP_FORMATION:
543 params.mode = IEEE80211_MODE_AP;
544 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800545 default:
546 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700548 if (ssid->frequency == 0)
549 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700550 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
554 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
555 else
556 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800557 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800559 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
560 1);
561 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
563 "cipher.");
564 return -1;
565 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800566 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 params.group_suite = params.pairwise_suite;
568
569#ifdef CONFIG_P2P
570 if (ssid->mode == WPAS_MODE_P2P_GO ||
571 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
572 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700573#endif /* CONFIG_P2P */
574
575 if (wpa_s->parent->set_ap_uapsd)
576 params.uapsd = wpa_s->parent->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800577 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
578 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700579 else
580 params.uapsd = -1;
581
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800582 if (ieee80211_is_dfs(params.freq.freq))
583 params.freq.freq = 0; /* set channel after CAC */
584
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585 if (wpa_drv_associate(wpa_s, &params) < 0) {
586 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
587 return -1;
588 }
589
590 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
591 if (hapd_iface == NULL)
592 return -1;
593 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800594 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800595 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800596 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700597 hapd_iface->extended_capa = wpa_s->extended_capa;
598 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
599 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600
601 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
602 if (conf == NULL) {
603 wpa_supplicant_ap_deinit(wpa_s);
604 return -1;
605 }
606
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700607 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
608 wpa_s->conf->wmm_ac_params,
609 sizeof(wpa_s->conf->wmm_ac_params));
610
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800611 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800612 conf->bss[0]->wmm_enabled = 1;
613 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800614 }
615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
617 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
618 wpa_supplicant_ap_deinit(wpa_s);
619 return -1;
620 }
621
622#ifdef CONFIG_P2P
623 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800624 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800626 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 P2P_GROUP_FORMATION;
628#endif /* CONFIG_P2P */
629
630 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700631 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632 sizeof(struct hostapd_data *));
633 if (hapd_iface->bss == NULL) {
634 wpa_supplicant_ap_deinit(wpa_s);
635 return -1;
636 }
637
638 for (i = 0; i < conf->num_bss; i++) {
639 hapd_iface->bss[i] =
640 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800641 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 if (hapd_iface->bss[i] == NULL) {
643 wpa_supplicant_ap_deinit(wpa_s);
644 return -1;
645 }
646
647 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -0700648 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
650 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
651 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
652 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
653 hostapd_register_probereq_cb(hapd_iface->bss[i],
654 ap_probe_req_rx, wpa_s);
655 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
656 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
657 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
658 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
659 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
660 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
661#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700662 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
663 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700665 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
666 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667#endif /* CONFIG_P2P */
668 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
669 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800670#ifdef CONFIG_TESTING_OPTIONS
671 hapd_iface->bss[i]->ext_eapol_frame_io =
672 wpa_s->ext_eapol_frame_io;
673#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674 }
675
676 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
677 hapd_iface->bss[0]->driver = wpa_s->driver;
678 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
679
680 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700681 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
683 wpa_s->assoc_freq = ssid->frequency;
684
685 if (hostapd_setup_interface(wpa_s->ap_iface)) {
686 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
687 wpa_supplicant_ap_deinit(wpa_s);
688 return -1;
689 }
690
691 return 0;
692}
693
694
695void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
696{
697#ifdef CONFIG_WPS
698 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
699#endif /* CONFIG_WPS */
700
701 if (wpa_s->ap_iface == NULL)
702 return;
703
704 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700705 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700707 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800708 wpa_s->ap_iface->driver_ap_teardown =
709 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 hostapd_interface_deinit(wpa_s->ap_iface);
712 hostapd_interface_free(wpa_s->ap_iface);
713 wpa_s->ap_iface = NULL;
714 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700715 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
716 " reason=%d locally_generated=1",
717 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718}
719
720
721void ap_tx_status(void *ctx, const u8 *addr,
722 const u8 *buf, size_t len, int ack)
723{
724#ifdef NEED_AP_MLME
725 struct wpa_supplicant *wpa_s = ctx;
726 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
727#endif /* NEED_AP_MLME */
728}
729
730
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800731void ap_eapol_tx_status(void *ctx, const u8 *dst,
732 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733{
734#ifdef NEED_AP_MLME
735 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800736 if (!wpa_s->ap_iface)
737 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800738 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
739#endif /* NEED_AP_MLME */
740}
741
742
743void ap_client_poll_ok(void *ctx, const u8 *addr)
744{
745#ifdef NEED_AP_MLME
746 struct wpa_supplicant *wpa_s = ctx;
747 if (wpa_s->ap_iface)
748 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
749#endif /* NEED_AP_MLME */
750}
751
752
753void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
754{
755#ifdef NEED_AP_MLME
756 struct wpa_supplicant *wpa_s = ctx;
757 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758#endif /* NEED_AP_MLME */
759}
760
761
762void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
763{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800764#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700765 struct wpa_supplicant *wpa_s = ctx;
766 struct hostapd_frame_info fi;
767 os_memset(&fi, 0, sizeof(fi));
768 fi.datarate = rx_mgmt->datarate;
769 fi.ssi_signal = rx_mgmt->ssi_signal;
770 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
771 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800772#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773}
774
775
776void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
777{
778#ifdef NEED_AP_MLME
779 struct wpa_supplicant *wpa_s = ctx;
780 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
781#endif /* NEED_AP_MLME */
782}
783
784
785void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
786 const u8 *src_addr, const u8 *buf, size_t len)
787{
788 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
789}
790
791
792#ifdef CONFIG_WPS
793
794int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
795 const u8 *p2p_dev_addr)
796{
797 if (!wpa_s->ap_iface)
798 return -1;
799 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
800 p2p_dev_addr);
801}
802
803
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
805{
806 struct wps_registrar *reg;
807 int reg_sel = 0, wps_sta = 0;
808
809 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
810 return -1;
811
812 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
813 reg_sel = wps_registrar_wps_cancel(reg);
814 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700815 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816
817 if (!reg_sel && !wps_sta) {
818 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
819 "time");
820 return -1;
821 }
822
823 /*
824 * There are 2 cases to return wps cancel as success:
825 * 1. When wps cancel was initiated but no connection has been
826 * established with client yet.
827 * 2. Client is in the middle of exchanging WPS messages.
828 */
829
830 return 0;
831}
832
833
834int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800835 const char *pin, char *buf, size_t buflen,
836 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837{
838 int ret, ret_len = 0;
839
840 if (!wpa_s->ap_iface)
841 return -1;
842
843 if (pin == NULL) {
844 unsigned int rpin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800845 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800846 if (os_snprintf_error(buflen, ret_len))
847 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800849 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800851 if (os_snprintf_error(buflen, ret_len))
852 return -1;
853 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854
855 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800856 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857 if (ret)
858 return -1;
859 return ret_len;
860}
861
862
863static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
864{
865 struct wpa_supplicant *wpa_s = eloop_data;
866 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
867 wpas_wps_ap_pin_disable(wpa_s);
868}
869
870
871static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
872{
873 struct hostapd_data *hapd;
874
875 if (wpa_s->ap_iface == NULL)
876 return;
877 hapd = wpa_s->ap_iface->bss[0];
878 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
879 hapd->ap_pin_failures = 0;
880 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
881 if (timeout > 0)
882 eloop_register_timeout(timeout, 0,
883 wpas_wps_ap_pin_timeout, wpa_s, NULL);
884}
885
886
887void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
888{
889 struct hostapd_data *hapd;
890
891 if (wpa_s->ap_iface == NULL)
892 return;
893 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
894 hapd = wpa_s->ap_iface->bss[0];
895 os_free(hapd->conf->ap_pin);
896 hapd->conf->ap_pin = NULL;
897 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
898}
899
900
901const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
902{
903 struct hostapd_data *hapd;
904 unsigned int pin;
905 char pin_txt[9];
906
907 if (wpa_s->ap_iface == NULL)
908 return NULL;
909 hapd = wpa_s->ap_iface->bss[0];
910 pin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800911 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 os_free(hapd->conf->ap_pin);
913 hapd->conf->ap_pin = os_strdup(pin_txt);
914 if (hapd->conf->ap_pin == NULL)
915 return NULL;
916 wpas_wps_ap_pin_enable(wpa_s, timeout);
917
918 return hapd->conf->ap_pin;
919}
920
921
922const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
923{
924 struct hostapd_data *hapd;
925 if (wpa_s->ap_iface == NULL)
926 return NULL;
927 hapd = wpa_s->ap_iface->bss[0];
928 return hapd->conf->ap_pin;
929}
930
931
932int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
933 int timeout)
934{
935 struct hostapd_data *hapd;
936 char pin_txt[9];
937 int ret;
938
939 if (wpa_s->ap_iface == NULL)
940 return -1;
941 hapd = wpa_s->ap_iface->bss[0];
942 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800943 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944 return -1;
945 os_free(hapd->conf->ap_pin);
946 hapd->conf->ap_pin = os_strdup(pin_txt);
947 if (hapd->conf->ap_pin == NULL)
948 return -1;
949 wpas_wps_ap_pin_enable(wpa_s, timeout);
950
951 return 0;
952}
953
954
955void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
956{
957 struct hostapd_data *hapd;
958
959 if (wpa_s->ap_iface == NULL)
960 return;
961 hapd = wpa_s->ap_iface->bss[0];
962
963 /*
964 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
965 * PIN if this happens multiple times to slow down brute force attacks.
966 */
967 hapd->ap_pin_failures++;
968 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
969 hapd->ap_pin_failures);
970 if (hapd->ap_pin_failures < 3)
971 return;
972
973 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
974 hapd->ap_pin_failures = 0;
975 os_free(hapd->conf->ap_pin);
976 hapd->conf->ap_pin = NULL;
977}
978
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800979
980#ifdef CONFIG_WPS_NFC
981
982struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
983 int ndef)
984{
985 struct hostapd_data *hapd;
986
987 if (wpa_s->ap_iface == NULL)
988 return NULL;
989 hapd = wpa_s->ap_iface->bss[0];
990 return hostapd_wps_nfc_config_token(hapd, ndef);
991}
992
993
994struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
995 int ndef)
996{
997 struct hostapd_data *hapd;
998
999 if (wpa_s->ap_iface == NULL)
1000 return NULL;
1001 hapd = wpa_s->ap_iface->bss[0];
1002 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1003}
1004
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001005
1006int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1007 const struct wpabuf *req,
1008 const struct wpabuf *sel)
1009{
1010 struct hostapd_data *hapd;
1011
1012 if (wpa_s->ap_iface == NULL)
1013 return -1;
1014 hapd = wpa_s->ap_iface->bss[0];
1015 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1016}
1017
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001018#endif /* CONFIG_WPS_NFC */
1019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020#endif /* CONFIG_WPS */
1021
1022
1023#ifdef CONFIG_CTRL_IFACE
1024
1025int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1026 char *buf, size_t buflen)
1027{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001028 struct hostapd_data *hapd;
1029
1030 if (wpa_s->ap_iface)
1031 hapd = wpa_s->ap_iface->bss[0];
1032 else if (wpa_s->ifmsh)
1033 hapd = wpa_s->ifmsh->bss[0];
1034 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001035 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001036 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037}
1038
1039
1040int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1041 char *buf, size_t buflen)
1042{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001043 struct hostapd_data *hapd;
1044
1045 if (wpa_s->ap_iface)
1046 hapd = wpa_s->ap_iface->bss[0];
1047 else if (wpa_s->ifmsh)
1048 hapd = wpa_s->ifmsh->bss[0];
1049 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001051 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052}
1053
1054
1055int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1056 char *buf, size_t buflen)
1057{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001058 struct hostapd_data *hapd;
1059
1060 if (wpa_s->ap_iface)
1061 hapd = wpa_s->ap_iface->bss[0];
1062 else if (wpa_s->ifmsh)
1063 hapd = wpa_s->ifmsh->bss[0];
1064 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001066 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067}
1068
1069
Dmitry Shmidt04949592012-07-19 12:16:46 -07001070int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1071 const char *txtaddr)
1072{
1073 if (wpa_s->ap_iface == NULL)
1074 return -1;
1075 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1076 txtaddr);
1077}
1078
1079
1080int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1081 const char *txtaddr)
1082{
1083 if (wpa_s->ap_iface == NULL)
1084 return -1;
1085 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1086 txtaddr);
1087}
1088
1089
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1091 size_t buflen, int verbose)
1092{
1093 char *pos = buf, *end = buf + buflen;
1094 int ret;
1095 struct hostapd_bss_config *conf;
1096
1097 if (wpa_s->ap_iface == NULL)
1098 return -1;
1099
1100 conf = wpa_s->ap_iface->bss[0]->conf;
1101 if (conf->wpa == 0)
1102 return 0;
1103
1104 ret = os_snprintf(pos, end - pos,
1105 "pairwise_cipher=%s\n"
1106 "group_cipher=%s\n"
1107 "key_mgmt=%s\n",
1108 wpa_cipher_txt(conf->rsn_pairwise),
1109 wpa_cipher_txt(conf->wpa_group),
1110 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1111 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001112 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 return pos - buf;
1114 pos += ret;
1115 return pos - buf;
1116}
1117
1118#endif /* CONFIG_CTRL_IFACE */
1119
1120
1121int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1122{
1123 struct hostapd_iface *iface = wpa_s->ap_iface;
1124 struct wpa_ssid *ssid = wpa_s->current_ssid;
1125 struct hostapd_data *hapd;
1126
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001127 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1128 ssid->mode == WPAS_MODE_INFRA ||
1129 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130 return -1;
1131
1132#ifdef CONFIG_P2P
1133 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001134 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001136 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001137 P2P_GROUP_FORMATION;
1138#endif /* CONFIG_P2P */
1139
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001141 if (hapd->drv_priv == NULL)
1142 return -1;
1143 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 hostapd_set_ap_wps_ie(hapd);
1145
1146 return 0;
1147}
1148
1149
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001150int ap_switch_channel(struct wpa_supplicant *wpa_s,
1151 struct csa_settings *settings)
1152{
1153#ifdef NEED_AP_MLME
1154 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1155 return -1;
1156
1157 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1158#else /* NEED_AP_MLME */
1159 return -1;
1160#endif /* NEED_AP_MLME */
1161}
1162
1163
Dmitry Shmidt83474442015-04-15 13:47:09 -07001164#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001165int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1166{
1167 struct csa_settings settings;
1168 int ret = hostapd_parse_csa_settings(pos, &settings);
1169
1170 if (ret)
1171 return ret;
1172
1173 return ap_switch_channel(wpa_s, &settings);
1174}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001175#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001176
1177
Dmitry Shmidt04949592012-07-19 12:16:46 -07001178void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001179 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001180{
1181 if (!wpa_s->ap_iface)
1182 return;
1183
1184 wpa_s->assoc_freq = freq;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001185 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001186}
1187
1188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1190 const u8 *addr)
1191{
1192 struct hostapd_data *hapd;
1193 struct hostapd_bss_config *conf;
1194
1195 if (!wpa_s->ap_iface)
1196 return -1;
1197
1198 if (addr)
1199 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1200 MAC2STR(addr));
1201 else
1202 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1203
1204 hapd = wpa_s->ap_iface->bss[0];
1205 conf = hapd->conf;
1206
1207 os_free(conf->accept_mac);
1208 conf->accept_mac = NULL;
1209 conf->num_accept_mac = 0;
1210 os_free(conf->deny_mac);
1211 conf->deny_mac = NULL;
1212 conf->num_deny_mac = 0;
1213
1214 if (addr == NULL) {
1215 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1216 return 0;
1217 }
1218
1219 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1220 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1221 if (conf->accept_mac == NULL)
1222 return -1;
1223 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1224 conf->num_accept_mac = 1;
1225
1226 return 0;
1227}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001228
1229
1230#ifdef CONFIG_WPS_NFC
1231int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1232 const struct wpabuf *pw, const u8 *pubkey_hash)
1233{
1234 struct hostapd_data *hapd;
1235 struct wps_context *wps;
1236
1237 if (!wpa_s->ap_iface)
1238 return -1;
1239 hapd = wpa_s->ap_iface->bss[0];
1240 wps = hapd->wps;
1241
1242 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1243 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1244 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1245 return -1;
1246 }
1247
1248 dh5_free(wps->dh_ctx);
1249 wpabuf_free(wps->dh_pubkey);
1250 wpabuf_free(wps->dh_privkey);
1251 wps->dh_privkey = wpabuf_dup(
1252 wpa_s->parent->conf->wps_nfc_dh_privkey);
1253 wps->dh_pubkey = wpabuf_dup(
1254 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1255 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1256 wps->dh_ctx = NULL;
1257 wpabuf_free(wps->dh_pubkey);
1258 wps->dh_pubkey = NULL;
1259 wpabuf_free(wps->dh_privkey);
1260 wps->dh_privkey = NULL;
1261 return -1;
1262 }
1263 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1264 if (wps->dh_ctx == NULL)
1265 return -1;
1266
1267 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1268 pw_id,
1269 pw ? wpabuf_head(pw) : NULL,
1270 pw ? wpabuf_len(pw) : 0, 1);
1271}
1272#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001273
1274
Dmitry Shmidt83474442015-04-15 13:47:09 -07001275#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001276int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1277{
1278 struct hostapd_data *hapd;
1279
1280 if (!wpa_s->ap_iface)
1281 return -1;
1282 hapd = wpa_s->ap_iface->bss[0];
1283 return hostapd_ctrl_iface_stop_ap(hapd);
1284}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001285#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001286
1287
1288#ifdef NEED_AP_MLME
1289void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1290 struct dfs_event *radar)
1291{
1292 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1293 return;
1294 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1295 hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
1296 radar->ht_enabled, radar->chan_offset,
1297 radar->chan_width,
1298 radar->cf1, radar->cf2);
1299}
1300
1301
1302void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1303 struct dfs_event *radar)
1304{
1305 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1306 return;
1307 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
1308 hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
1309 radar->ht_enabled, radar->chan_offset,
1310 radar->chan_width, radar->cf1, radar->cf2);
1311}
1312
1313
1314void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1315 struct dfs_event *radar)
1316{
1317 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1318 return;
1319 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1320 hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
1321 radar->ht_enabled, radar->chan_offset,
1322 radar->chan_width, radar->cf1, radar->cf2);
1323}
1324
1325
1326void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1327 struct dfs_event *radar)
1328{
1329 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1330 return;
1331 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1332 hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
1333 radar->ht_enabled, radar->chan_offset,
1334 radar->chan_width, radar->cf1, radar->cf2);
1335}
1336
1337
1338void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1339 struct dfs_event *radar)
1340{
1341 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1342 return;
1343 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1344 hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
1345 radar->ht_enabled, radar->chan_offset,
1346 radar->chan_width, radar->cf1, radar->cf2);
1347}
1348#endif /* NEED_AP_MLME */