blob: 65532e3cb1bc448933aeb5cc2084d5a366d5ca21 [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 Shmidt8d520ff2011-05-09 14:06:53 -070029#include "wps/wps.h"
30#include "common/ieee802_11_defs.h"
31#include "config_ssid.h"
32#include "config.h"
33#include "wpa_supplicant_i.h"
34#include "driver_i.h"
35#include "p2p_supplicant.h"
36#include "ap.h"
37#include "ap/sta_info.h"
38#include "notify.h"
39
40
41#ifdef CONFIG_WPS
42static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
43#endif /* CONFIG_WPS */
44
45
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070046#ifdef CONFIG_IEEE80211N
47static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
48 struct hostapd_config *conf,
49 struct hostapd_hw_modes *mode)
50{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070051#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070052 u8 center_chan = 0;
53 u8 channel = conf->channel;
54
55 if (!conf->secondary_channel)
56 goto no_vht;
57
58 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
59 if (!center_chan)
60 goto no_vht;
61
62 /* Use 80 MHz channel */
63 conf->vht_oper_chwidth = 1;
64 conf->vht_oper_centr_freq_seg0_idx = center_chan;
65 return;
66
67no_vht:
68 conf->vht_oper_centr_freq_seg0_idx =
69 channel + conf->secondary_channel * 2;
Dmitry Shmidt21de2142014-04-08 10:50:52 -070070#else /* CONFIG_P2P */
71 conf->vht_oper_centr_freq_seg0_idx =
72 conf->channel + conf->secondary_channel * 2;
73#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070074}
75#endif /* CONFIG_IEEE80211N */
76
77
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080078void wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
79 struct wpa_ssid *ssid,
80 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070081{
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070082 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 * drop to 11b if driver does not support 11g */
84
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070085#ifdef CONFIG_IEEE80211N
86 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080087 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
88 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070089 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080090 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070091 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080092 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070093 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -070094 int i, no_ht = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080095 for (i = 0; i < wpa_s->hw.num_modes; i++) {
96 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
97 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070098 break;
99 }
100 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700101
102#ifdef CONFIG_HT_OVERRIDES
103 if (ssid->disable_ht) {
104 conf->ieee80211n = 0;
105 conf->ht_capab = 0;
106 no_ht = 1;
107 }
108#endif /* CONFIG_HT_OVERRIDES */
109
110 if (!no_ht && mode && mode->ht_capab) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700111 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700112#ifdef CONFIG_P2P
113 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
114 (mode->ht_capab &
115 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
116 ssid->ht40)
117 conf->secondary_channel =
118 wpas_p2p_get_ht40_mode(wpa_s, mode,
119 conf->channel);
120 if (conf->secondary_channel)
121 conf->ht_capab |=
122 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
123#endif /* CONFIG_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800124
125 /*
126 * white-list capabilities that won't cause issues
127 * to connecting stations, while leaving the current
128 * capabilities intact (currently disabled SMPS).
129 */
130 conf->ht_capab |= mode->ht_capab &
131 (HT_CAP_INFO_GREEN_FIELD |
132 HT_CAP_INFO_SHORT_GI20MHZ |
133 HT_CAP_INFO_SHORT_GI40MHZ |
134 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800135 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800136 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700137
138 if (mode->vht_capab && ssid->vht) {
139 conf->ieee80211ac = 1;
140 wpas_conf_ap_vht(wpa_s, conf, mode);
141 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800142 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700143 }
144#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800145}
146
147
148static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
149 struct wpa_ssid *ssid,
150 struct hostapd_config *conf)
151{
152 struct hostapd_bss_config *bss = conf->bss[0];
153
154 conf->driver = wpa_s->driver;
155
156 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
157
158 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
159 &conf->channel);
160 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
161 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
162 ssid->frequency);
163 return -1;
164 }
165
166 wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700169 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
170 (ssid->mode == WPAS_MODE_P2P_GO ||
171 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 /* Remove 802.11b rates from supported and basic rate sets */
173 int *list = os_malloc(4 * sizeof(int));
174 if (list) {
175 list[0] = 60;
176 list[1] = 120;
177 list[2] = 240;
178 list[3] = -1;
179 }
180 conf->basic_rates = list;
181
182 list = os_malloc(9 * sizeof(int));
183 if (list) {
184 list[0] = 60;
185 list[1] = 90;
186 list[2] = 120;
187 list[3] = 180;
188 list[4] = 240;
189 list[5] = 360;
190 list[6] = 480;
191 list[7] = 540;
192 list[8] = -1;
193 }
194 conf->supported_rates = list;
195 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800196
197 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700198 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800199
200 if (ssid->p2p_group) {
201 os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
202 os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
203 4);
204 os_memcpy(bss->ip_addr_start,
205 wpa_s->parent->conf->ip_addr_start, 4);
206 os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
207 4);
208 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700209#endif /* CONFIG_P2P */
210
211 if (ssid->ssid_len == 0) {
212 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
213 return -1;
214 }
215 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216 bss->ssid.ssid_len = ssid->ssid_len;
217 bss->ssid.ssid_set = 1;
218
Dmitry Shmidt04949592012-07-19 12:16:46 -0700219 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
220
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800221 if (ssid->auth_alg)
222 bss->auth_algs = ssid->auth_alg;
223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
225 bss->wpa = ssid->proto;
226 bss->wpa_key_mgmt = ssid->key_mgmt;
227 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800228 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800229 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
231 if (bss->ssid.wpa_psk == NULL)
232 return -1;
233 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
234 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800235 } else if (ssid->passphrase) {
236 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800237 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
238 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
239 struct hostapd_wep_keys *wep = &bss->ssid.wep;
240 int i;
241 for (i = 0; i < NUM_WEP_KEYS; i++) {
242 if (ssid->wep_key_len[i] == 0)
243 continue;
244 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
245 if (wep->key[i] == NULL)
246 return -1;
247 os_memcpy(wep->key[i], ssid->wep_key[i],
248 ssid->wep_key_len[i]);
249 wep->len[i] = ssid->wep_key_len[i];
250 }
251 wep->idx = ssid->wep_tx_keyidx;
252 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 }
254
Dmitry Shmidt04949592012-07-19 12:16:46 -0700255 if (ssid->ap_max_inactivity)
256 bss->ap_max_inactivity = ssid->ap_max_inactivity;
257
258 if (ssid->dtim_period)
259 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800260 else if (wpa_s->conf->dtim_period)
261 bss->dtim_period = wpa_s->conf->dtim_period;
262
263 if (ssid->beacon_int)
264 conf->beacon_int = ssid->beacon_int;
265 else if (wpa_s->conf->beacon_int)
266 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700267
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800268 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
269 bss->rsn_pairwise = bss->wpa_pairwise;
270 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
271 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272
273 if (bss->wpa && bss->ieee802_1x)
274 bss->ssid.security_policy = SECURITY_WPA;
275 else if (bss->wpa)
276 bss->ssid.security_policy = SECURITY_WPA_PSK;
277 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
280 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800281 if (bss->default_wep_key_len)
282 cipher = bss->default_wep_key_len >= 13 ?
283 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
284 bss->wpa_group = cipher;
285 bss->wpa_pairwise = cipher;
286 bss->rsn_pairwise = cipher;
287 } else if (bss->ssid.wep.keys_set) {
288 int cipher = WPA_CIPHER_WEP40;
289 if (bss->ssid.wep.len[0] >= 13)
290 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800292 bss->wpa_group = cipher;
293 bss->wpa_pairwise = cipher;
294 bss->rsn_pairwise = cipher;
295 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800297 bss->wpa_group = WPA_CIPHER_NONE;
298 bss->wpa_pairwise = WPA_CIPHER_NONE;
299 bss->rsn_pairwise = WPA_CIPHER_NONE;
300 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700302 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
303 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800304 bss->wpa_group == WPA_CIPHER_GCMP ||
305 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
306 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700307 /*
308 * Strong ciphers do not need frequent rekeying, so increase
309 * the default GTK rekeying period to 24 hours.
310 */
311 bss->wpa_group_rekey = 86400;
312 }
313
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700314#ifdef CONFIG_IEEE80211W
315 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
316 bss->ieee80211w = ssid->ieee80211w;
317#endif /* CONFIG_IEEE80211W */
318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319#ifdef CONFIG_WPS
320 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800321 * Enable WPS by default for open and WPA/WPA2-Personal network, but
322 * require user interaction to actually use it. Only the internal
323 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800325 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
326 bss->ssid.security_policy != SECURITY_PLAINTEXT)
327 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800329 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
330 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800331 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
332 * configuration */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700334
335 if (!ssid->ignore_broadcast_ssid)
336 bss->wps_state = 2;
337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 bss->ap_setup_locked = 2;
339 if (wpa_s->conf->config_methods)
340 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
341 os_memcpy(bss->device_type, wpa_s->conf->device_type,
342 WPS_DEV_TYPE_LEN);
343 if (wpa_s->conf->device_name) {
344 bss->device_name = os_strdup(wpa_s->conf->device_name);
345 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
346 }
347 if (wpa_s->conf->manufacturer)
348 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
349 if (wpa_s->conf->model_name)
350 bss->model_name = os_strdup(wpa_s->conf->model_name);
351 if (wpa_s->conf->model_number)
352 bss->model_number = os_strdup(wpa_s->conf->model_number);
353 if (wpa_s->conf->serial_number)
354 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
355 if (is_nil_uuid(wpa_s->conf->uuid))
356 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
357 else
358 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
359 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700360 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800361no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362#endif /* CONFIG_WPS */
363
364 if (wpa_s->max_stations &&
365 wpa_s->max_stations < wpa_s->conf->max_num_sta)
366 bss->max_num_sta = wpa_s->max_stations;
367 else
368 bss->max_num_sta = wpa_s->conf->max_num_sta;
369
370 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
371
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700372 if (wpa_s->conf->ap_vendor_elements) {
373 bss->vendor_elements =
374 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
375 }
376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 return 0;
378}
379
380
381static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
382{
383#ifdef CONFIG_P2P
384 struct wpa_supplicant *wpa_s = ctx;
385 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386
387 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700388 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700389 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800390 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
391 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
393 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700394 buf + IEEE80211_HDRLEN + 1,
395 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396#endif /* CONFIG_P2P */
397}
398
399
400static void ap_wps_event_cb(void *ctx, enum wps_event event,
401 union wps_event_data *data)
402{
403#ifdef CONFIG_P2P
404 struct wpa_supplicant *wpa_s = ctx;
405
Jouni Malinen75ecf522011-06-27 15:19:46 -0700406 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 struct wps_event_fail *fail = &data->fail;
408
Jouni Malinen75ecf522011-06-27 15:19:46 -0700409 if (wpa_s->parent && wpa_s->parent != wpa_s &&
410 wpa_s == wpa_s->global->p2p_group_formation) {
411 /*
412 * src/ap/wps_hostapd.c has already sent this on the
413 * main interface, so only send on the parent interface
414 * here if needed.
415 */
416 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
417 "msg=%d config_error=%d",
418 fail->msg, fail->config_error);
419 }
420 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 }
422#endif /* CONFIG_P2P */
423}
424
425
426static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800427 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800429 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430}
431
432
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700433#ifdef CONFIG_P2P
434static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
435 const u8 *psk, size_t psk_len)
436{
437
438 struct wpa_supplicant *wpa_s = ctx;
439 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
440 return;
441 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
442}
443#endif /* CONFIG_P2P */
444
445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
447{
448#ifdef CONFIG_P2P
449 struct wpa_supplicant *wpa_s = ctx;
450 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451
452 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700453 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 return -1;
455 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
456 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700457 buf + IEEE80211_HDRLEN + 1,
458 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700459#endif /* CONFIG_P2P */
460 return 0;
461}
462
463
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800464static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700465 const u8 *bssid, const u8 *ie, size_t ie_len,
466 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700469 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
470 ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471}
472
473
474static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
475 const u8 *uuid_e)
476{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 struct wpa_supplicant *wpa_s = ctx;
478 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479}
480
481
482static void wpas_ap_configured_cb(void *ctx)
483{
484 struct wpa_supplicant *wpa_s = ctx;
485
486 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
487
488 if (wpa_s->ap_configured_cb)
489 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
490 wpa_s->ap_configured_cb_data);
491}
492
493
494int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
495 struct wpa_ssid *ssid)
496{
497 struct wpa_driver_associate_params params;
498 struct hostapd_iface *hapd_iface;
499 struct hostapd_config *conf;
500 size_t i;
501
502 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
503 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
504 return -1;
505 }
506
507 wpa_supplicant_ap_deinit(wpa_s);
508
509 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
510 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
511
512 os_memset(&params, 0, sizeof(params));
513 params.ssid = ssid->ssid;
514 params.ssid_len = ssid->ssid_len;
515 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 case WPAS_MODE_AP:
517 case WPAS_MODE_P2P_GO:
518 case WPAS_MODE_P2P_GROUP_FORMATION:
519 params.mode = IEEE80211_MODE_AP;
520 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800521 default:
522 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700524 if (ssid->frequency == 0)
525 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700526 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800528 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
530 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
531 else
532 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800533 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800535 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
536 1);
537 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
539 "cipher.");
540 return -1;
541 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800542 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 params.group_suite = params.pairwise_suite;
544
545#ifdef CONFIG_P2P
546 if (ssid->mode == WPAS_MODE_P2P_GO ||
547 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
548 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549#endif /* CONFIG_P2P */
550
551 if (wpa_s->parent->set_ap_uapsd)
552 params.uapsd = wpa_s->parent->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800553 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
554 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 else
556 params.uapsd = -1;
557
558 if (wpa_drv_associate(wpa_s, &params) < 0) {
559 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
560 return -1;
561 }
562
563 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
564 if (hapd_iface == NULL)
565 return -1;
566 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800567 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800568 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800569 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700570 hapd_iface->extended_capa = wpa_s->extended_capa;
571 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
572 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700573
574 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
575 if (conf == NULL) {
576 wpa_supplicant_ap_deinit(wpa_s);
577 return -1;
578 }
579
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700580 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
581 wpa_s->conf->wmm_ac_params,
582 sizeof(wpa_s->conf->wmm_ac_params));
583
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800584 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800585 conf->bss[0]->wmm_enabled = 1;
586 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800587 }
588
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
590 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
591 wpa_supplicant_ap_deinit(wpa_s);
592 return -1;
593 }
594
595#ifdef CONFIG_P2P
596 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800597 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800599 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600 P2P_GROUP_FORMATION;
601#endif /* CONFIG_P2P */
602
603 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700604 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605 sizeof(struct hostapd_data *));
606 if (hapd_iface->bss == NULL) {
607 wpa_supplicant_ap_deinit(wpa_s);
608 return -1;
609 }
610
611 for (i = 0; i < conf->num_bss; i++) {
612 hapd_iface->bss[i] =
613 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800614 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700615 if (hapd_iface->bss[i] == NULL) {
616 wpa_supplicant_ap_deinit(wpa_s);
617 return -1;
618 }
619
620 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -0700621 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700622 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
623 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
624 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
625 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
626 hostapd_register_probereq_cb(hapd_iface->bss[i],
627 ap_probe_req_rx, wpa_s);
628 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
629 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
630 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
631 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
632 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
633 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
634#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700635 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
636 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700638 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
639 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640#endif /* CONFIG_P2P */
641 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
642 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800643#ifdef CONFIG_TESTING_OPTIONS
644 hapd_iface->bss[i]->ext_eapol_frame_io =
645 wpa_s->ext_eapol_frame_io;
646#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 }
648
649 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
650 hapd_iface->bss[0]->driver = wpa_s->driver;
651 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
652
653 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700654 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
656 wpa_s->assoc_freq = ssid->frequency;
657
658 if (hostapd_setup_interface(wpa_s->ap_iface)) {
659 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
660 wpa_supplicant_ap_deinit(wpa_s);
661 return -1;
662 }
663
664 return 0;
665}
666
667
668void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
669{
670#ifdef CONFIG_WPS
671 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
672#endif /* CONFIG_WPS */
673
674 if (wpa_s->ap_iface == NULL)
675 return;
676
677 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700678 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700680 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800681 wpa_s->ap_iface->driver_ap_teardown =
682 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
683
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 hostapd_interface_deinit(wpa_s->ap_iface);
685 hostapd_interface_free(wpa_s->ap_iface);
686 wpa_s->ap_iface = NULL;
687 wpa_drv_deinit_ap(wpa_s);
688}
689
690
691void ap_tx_status(void *ctx, const u8 *addr,
692 const u8 *buf, size_t len, int ack)
693{
694#ifdef NEED_AP_MLME
695 struct wpa_supplicant *wpa_s = ctx;
696 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
697#endif /* NEED_AP_MLME */
698}
699
700
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800701void ap_eapol_tx_status(void *ctx, const u8 *dst,
702 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703{
704#ifdef NEED_AP_MLME
705 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800706 if (!wpa_s->ap_iface)
707 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800708 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
709#endif /* NEED_AP_MLME */
710}
711
712
713void ap_client_poll_ok(void *ctx, const u8 *addr)
714{
715#ifdef NEED_AP_MLME
716 struct wpa_supplicant *wpa_s = ctx;
717 if (wpa_s->ap_iface)
718 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
719#endif /* NEED_AP_MLME */
720}
721
722
723void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
724{
725#ifdef NEED_AP_MLME
726 struct wpa_supplicant *wpa_s = ctx;
727 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728#endif /* NEED_AP_MLME */
729}
730
731
732void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
733{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800734#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735 struct wpa_supplicant *wpa_s = ctx;
736 struct hostapd_frame_info fi;
737 os_memset(&fi, 0, sizeof(fi));
738 fi.datarate = rx_mgmt->datarate;
739 fi.ssi_signal = rx_mgmt->ssi_signal;
740 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
741 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800742#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743}
744
745
746void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
747{
748#ifdef NEED_AP_MLME
749 struct wpa_supplicant *wpa_s = ctx;
750 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
751#endif /* NEED_AP_MLME */
752}
753
754
755void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
756 const u8 *src_addr, const u8 *buf, size_t len)
757{
758 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
759}
760
761
762#ifdef CONFIG_WPS
763
764int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
765 const u8 *p2p_dev_addr)
766{
767 if (!wpa_s->ap_iface)
768 return -1;
769 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
770 p2p_dev_addr);
771}
772
773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
775{
776 struct wps_registrar *reg;
777 int reg_sel = 0, wps_sta = 0;
778
779 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
780 return -1;
781
782 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
783 reg_sel = wps_registrar_wps_cancel(reg);
784 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700785 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786
787 if (!reg_sel && !wps_sta) {
788 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
789 "time");
790 return -1;
791 }
792
793 /*
794 * There are 2 cases to return wps cancel as success:
795 * 1. When wps cancel was initiated but no connection has been
796 * established with client yet.
797 * 2. Client is in the middle of exchanging WPS messages.
798 */
799
800 return 0;
801}
802
803
804int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800805 const char *pin, char *buf, size_t buflen,
806 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807{
808 int ret, ret_len = 0;
809
810 if (!wpa_s->ap_iface)
811 return -1;
812
813 if (pin == NULL) {
814 unsigned int rpin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800815 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800816 if (os_snprintf_error(buflen, ret_len))
817 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700818 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800819 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800821 if (os_snprintf_error(buflen, ret_len))
822 return -1;
823 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824
825 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800826 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 if (ret)
828 return -1;
829 return ret_len;
830}
831
832
833static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
834{
835 struct wpa_supplicant *wpa_s = eloop_data;
836 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
837 wpas_wps_ap_pin_disable(wpa_s);
838}
839
840
841static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
842{
843 struct hostapd_data *hapd;
844
845 if (wpa_s->ap_iface == NULL)
846 return;
847 hapd = wpa_s->ap_iface->bss[0];
848 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
849 hapd->ap_pin_failures = 0;
850 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
851 if (timeout > 0)
852 eloop_register_timeout(timeout, 0,
853 wpas_wps_ap_pin_timeout, wpa_s, NULL);
854}
855
856
857void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
858{
859 struct hostapd_data *hapd;
860
861 if (wpa_s->ap_iface == NULL)
862 return;
863 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
864 hapd = wpa_s->ap_iface->bss[0];
865 os_free(hapd->conf->ap_pin);
866 hapd->conf->ap_pin = NULL;
867 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
868}
869
870
871const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
872{
873 struct hostapd_data *hapd;
874 unsigned int pin;
875 char pin_txt[9];
876
877 if (wpa_s->ap_iface == NULL)
878 return NULL;
879 hapd = wpa_s->ap_iface->bss[0];
880 pin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800881 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 os_free(hapd->conf->ap_pin);
883 hapd->conf->ap_pin = os_strdup(pin_txt);
884 if (hapd->conf->ap_pin == NULL)
885 return NULL;
886 wpas_wps_ap_pin_enable(wpa_s, timeout);
887
888 return hapd->conf->ap_pin;
889}
890
891
892const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
893{
894 struct hostapd_data *hapd;
895 if (wpa_s->ap_iface == NULL)
896 return NULL;
897 hapd = wpa_s->ap_iface->bss[0];
898 return hapd->conf->ap_pin;
899}
900
901
902int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
903 int timeout)
904{
905 struct hostapd_data *hapd;
906 char pin_txt[9];
907 int ret;
908
909 if (wpa_s->ap_iface == NULL)
910 return -1;
911 hapd = wpa_s->ap_iface->bss[0];
912 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800913 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 return -1;
915 os_free(hapd->conf->ap_pin);
916 hapd->conf->ap_pin = os_strdup(pin_txt);
917 if (hapd->conf->ap_pin == NULL)
918 return -1;
919 wpas_wps_ap_pin_enable(wpa_s, timeout);
920
921 return 0;
922}
923
924
925void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
926{
927 struct hostapd_data *hapd;
928
929 if (wpa_s->ap_iface == NULL)
930 return;
931 hapd = wpa_s->ap_iface->bss[0];
932
933 /*
934 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
935 * PIN if this happens multiple times to slow down brute force attacks.
936 */
937 hapd->ap_pin_failures++;
938 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
939 hapd->ap_pin_failures);
940 if (hapd->ap_pin_failures < 3)
941 return;
942
943 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
944 hapd->ap_pin_failures = 0;
945 os_free(hapd->conf->ap_pin);
946 hapd->conf->ap_pin = NULL;
947}
948
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800949
950#ifdef CONFIG_WPS_NFC
951
952struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
953 int ndef)
954{
955 struct hostapd_data *hapd;
956
957 if (wpa_s->ap_iface == NULL)
958 return NULL;
959 hapd = wpa_s->ap_iface->bss[0];
960 return hostapd_wps_nfc_config_token(hapd, ndef);
961}
962
963
964struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
965 int ndef)
966{
967 struct hostapd_data *hapd;
968
969 if (wpa_s->ap_iface == NULL)
970 return NULL;
971 hapd = wpa_s->ap_iface->bss[0];
972 return hostapd_wps_nfc_hs_cr(hapd, ndef);
973}
974
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800975
976int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
977 const struct wpabuf *req,
978 const struct wpabuf *sel)
979{
980 struct hostapd_data *hapd;
981
982 if (wpa_s->ap_iface == NULL)
983 return -1;
984 hapd = wpa_s->ap_iface->bss[0];
985 return hostapd_wps_nfc_report_handover(hapd, req, sel);
986}
987
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800988#endif /* CONFIG_WPS_NFC */
989
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990#endif /* CONFIG_WPS */
991
992
993#ifdef CONFIG_CTRL_IFACE
994
995int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
996 char *buf, size_t buflen)
997{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800998 struct hostapd_data *hapd;
999
1000 if (wpa_s->ap_iface)
1001 hapd = wpa_s->ap_iface->bss[0];
1002 else if (wpa_s->ifmsh)
1003 hapd = wpa_s->ifmsh->bss[0];
1004 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001006 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007}
1008
1009
1010int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1011 char *buf, size_t buflen)
1012{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001013 struct hostapd_data *hapd;
1014
1015 if (wpa_s->ap_iface)
1016 hapd = wpa_s->ap_iface->bss[0];
1017 else if (wpa_s->ifmsh)
1018 hapd = wpa_s->ifmsh->bss[0];
1019 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001021 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022}
1023
1024
1025int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
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_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037}
1038
1039
Dmitry Shmidt04949592012-07-19 12:16:46 -07001040int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1041 const char *txtaddr)
1042{
1043 if (wpa_s->ap_iface == NULL)
1044 return -1;
1045 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1046 txtaddr);
1047}
1048
1049
1050int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1051 const char *txtaddr)
1052{
1053 if (wpa_s->ap_iface == NULL)
1054 return -1;
1055 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1056 txtaddr);
1057}
1058
1059
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1061 size_t buflen, int verbose)
1062{
1063 char *pos = buf, *end = buf + buflen;
1064 int ret;
1065 struct hostapd_bss_config *conf;
1066
1067 if (wpa_s->ap_iface == NULL)
1068 return -1;
1069
1070 conf = wpa_s->ap_iface->bss[0]->conf;
1071 if (conf->wpa == 0)
1072 return 0;
1073
1074 ret = os_snprintf(pos, end - pos,
1075 "pairwise_cipher=%s\n"
1076 "group_cipher=%s\n"
1077 "key_mgmt=%s\n",
1078 wpa_cipher_txt(conf->rsn_pairwise),
1079 wpa_cipher_txt(conf->wpa_group),
1080 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1081 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001082 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 return pos - buf;
1084 pos += ret;
1085 return pos - buf;
1086}
1087
1088#endif /* CONFIG_CTRL_IFACE */
1089
1090
1091int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1092{
1093 struct hostapd_iface *iface = wpa_s->ap_iface;
1094 struct wpa_ssid *ssid = wpa_s->current_ssid;
1095 struct hostapd_data *hapd;
1096
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001097 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1098 ssid->mode == WPAS_MODE_INFRA ||
1099 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100 return -1;
1101
1102#ifdef CONFIG_P2P
1103 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001104 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001106 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107 P2P_GROUP_FORMATION;
1108#endif /* CONFIG_P2P */
1109
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001111 if (hapd->drv_priv == NULL)
1112 return -1;
1113 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001114 hostapd_set_ap_wps_ie(hapd);
1115
1116 return 0;
1117}
1118
1119
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001120int ap_switch_channel(struct wpa_supplicant *wpa_s,
1121 struct csa_settings *settings)
1122{
1123#ifdef NEED_AP_MLME
1124 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1125 return -1;
1126
1127 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1128#else /* NEED_AP_MLME */
1129 return -1;
1130#endif /* NEED_AP_MLME */
1131}
1132
1133
1134int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1135{
1136 struct csa_settings settings;
1137 int ret = hostapd_parse_csa_settings(pos, &settings);
1138
1139 if (ret)
1140 return ret;
1141
1142 return ap_switch_channel(wpa_s, &settings);
1143}
1144
1145
Dmitry Shmidt04949592012-07-19 12:16:46 -07001146void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001147 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001148{
1149 if (!wpa_s->ap_iface)
1150 return;
1151
1152 wpa_s->assoc_freq = freq;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001153 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001154}
1155
1156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1158 const u8 *addr)
1159{
1160 struct hostapd_data *hapd;
1161 struct hostapd_bss_config *conf;
1162
1163 if (!wpa_s->ap_iface)
1164 return -1;
1165
1166 if (addr)
1167 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1168 MAC2STR(addr));
1169 else
1170 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1171
1172 hapd = wpa_s->ap_iface->bss[0];
1173 conf = hapd->conf;
1174
1175 os_free(conf->accept_mac);
1176 conf->accept_mac = NULL;
1177 conf->num_accept_mac = 0;
1178 os_free(conf->deny_mac);
1179 conf->deny_mac = NULL;
1180 conf->num_deny_mac = 0;
1181
1182 if (addr == NULL) {
1183 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1184 return 0;
1185 }
1186
1187 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1188 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1189 if (conf->accept_mac == NULL)
1190 return -1;
1191 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1192 conf->num_accept_mac = 1;
1193
1194 return 0;
1195}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001196
1197
1198#ifdef CONFIG_WPS_NFC
1199int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1200 const struct wpabuf *pw, const u8 *pubkey_hash)
1201{
1202 struct hostapd_data *hapd;
1203 struct wps_context *wps;
1204
1205 if (!wpa_s->ap_iface)
1206 return -1;
1207 hapd = wpa_s->ap_iface->bss[0];
1208 wps = hapd->wps;
1209
1210 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1211 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1212 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1213 return -1;
1214 }
1215
1216 dh5_free(wps->dh_ctx);
1217 wpabuf_free(wps->dh_pubkey);
1218 wpabuf_free(wps->dh_privkey);
1219 wps->dh_privkey = wpabuf_dup(
1220 wpa_s->parent->conf->wps_nfc_dh_privkey);
1221 wps->dh_pubkey = wpabuf_dup(
1222 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1223 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1224 wps->dh_ctx = NULL;
1225 wpabuf_free(wps->dh_pubkey);
1226 wps->dh_pubkey = NULL;
1227 wpabuf_free(wps->dh_privkey);
1228 wps->dh_privkey = NULL;
1229 return -1;
1230 }
1231 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1232 if (wps->dh_ctx == NULL)
1233 return -1;
1234
1235 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1236 pw_id,
1237 pw ? wpabuf_head(pw) : NULL,
1238 pw ? wpabuf_len(pw) : 0, 1);
1239}
1240#endif /* CONFIG_WPS_NFC */