blob: 4ff27d6c99933bd831dc96a6c023efb4ce9bc08a [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{
51 u8 center_chan = 0;
52 u8 channel = conf->channel;
53
54 if (!conf->secondary_channel)
55 goto no_vht;
56
57 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
58 if (!center_chan)
59 goto no_vht;
60
61 /* Use 80 MHz channel */
62 conf->vht_oper_chwidth = 1;
63 conf->vht_oper_centr_freq_seg0_idx = center_chan;
64 return;
65
66no_vht:
67 conf->vht_oper_centr_freq_seg0_idx =
68 channel + conf->secondary_channel * 2;
69}
70#endif /* CONFIG_IEEE80211N */
71
72
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
74 struct wpa_ssid *ssid,
75 struct hostapd_config *conf)
76{
Dmitry Shmidtcce06662013-11-04 18:44:24 -080077 struct hostapd_bss_config *bss = conf->bss[0];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070078
79 conf->driver = wpa_s->driver;
80
81 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
82
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070083 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
84 &conf->channel);
85 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
86 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
87 ssid->frequency);
88 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 }
90
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070091 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092 * drop to 11b if driver does not support 11g */
93
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070094#ifdef CONFIG_IEEE80211N
95 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080096 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
97 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070098 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080099 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700100 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800101 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700102 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700103 int i, no_ht = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800104 for (i = 0; i < wpa_s->hw.num_modes; i++) {
105 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
106 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700107 break;
108 }
109 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700110
111#ifdef CONFIG_HT_OVERRIDES
112 if (ssid->disable_ht) {
113 conf->ieee80211n = 0;
114 conf->ht_capab = 0;
115 no_ht = 1;
116 }
117#endif /* CONFIG_HT_OVERRIDES */
118
119 if (!no_ht && mode && mode->ht_capab) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700120 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700121#ifdef CONFIG_P2P
122 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
123 (mode->ht_capab &
124 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
125 ssid->ht40)
126 conf->secondary_channel =
127 wpas_p2p_get_ht40_mode(wpa_s, mode,
128 conf->channel);
129 if (conf->secondary_channel)
130 conf->ht_capab |=
131 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
132#endif /* CONFIG_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800133
134 /*
135 * white-list capabilities that won't cause issues
136 * to connecting stations, while leaving the current
137 * capabilities intact (currently disabled SMPS).
138 */
139 conf->ht_capab |= mode->ht_capab &
140 (HT_CAP_INFO_GREEN_FIELD |
141 HT_CAP_INFO_SHORT_GI20MHZ |
142 HT_CAP_INFO_SHORT_GI40MHZ |
143 HT_CAP_INFO_RX_STBC_MASK |
144 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700145
146 if (mode->vht_capab && ssid->vht) {
147 conf->ieee80211ac = 1;
148 wpas_conf_ap_vht(wpa_s, conf, mode);
149 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800150 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700151 }
152#endif /* CONFIG_IEEE80211N */
153
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700155 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
156 (ssid->mode == WPAS_MODE_P2P_GO ||
157 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700158 /* Remove 802.11b rates from supported and basic rate sets */
159 int *list = os_malloc(4 * sizeof(int));
160 if (list) {
161 list[0] = 60;
162 list[1] = 120;
163 list[2] = 240;
164 list[3] = -1;
165 }
166 conf->basic_rates = list;
167
168 list = os_malloc(9 * sizeof(int));
169 if (list) {
170 list[0] = 60;
171 list[1] = 90;
172 list[2] = 120;
173 list[3] = 180;
174 list[4] = 240;
175 list[5] = 360;
176 list[6] = 480;
177 list[7] = 540;
178 list[8] = -1;
179 }
180 conf->supported_rates = list;
181 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800182
183 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700184 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800185
186 if (ssid->p2p_group) {
187 os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
188 os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
189 4);
190 os_memcpy(bss->ip_addr_start,
191 wpa_s->parent->conf->ip_addr_start, 4);
192 os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
193 4);
194 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195#endif /* CONFIG_P2P */
196
197 if (ssid->ssid_len == 0) {
198 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
199 return -1;
200 }
201 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 bss->ssid.ssid_len = ssid->ssid_len;
203 bss->ssid.ssid_set = 1;
204
Dmitry Shmidt04949592012-07-19 12:16:46 -0700205 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
206
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800207 if (ssid->auth_alg)
208 bss->auth_algs = ssid->auth_alg;
209
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700210 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
211 bss->wpa = ssid->proto;
212 bss->wpa_key_mgmt = ssid->key_mgmt;
213 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800214 if (ssid->psk_set) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700215 os_free(bss->ssid.wpa_psk);
216 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
217 if (bss->ssid.wpa_psk == NULL)
218 return -1;
219 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
220 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800221 } else if (ssid->passphrase) {
222 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800223 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
224 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
225 struct hostapd_wep_keys *wep = &bss->ssid.wep;
226 int i;
227 for (i = 0; i < NUM_WEP_KEYS; i++) {
228 if (ssid->wep_key_len[i] == 0)
229 continue;
230 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
231 if (wep->key[i] == NULL)
232 return -1;
233 os_memcpy(wep->key[i], ssid->wep_key[i],
234 ssid->wep_key_len[i]);
235 wep->len[i] = ssid->wep_key_len[i];
236 }
237 wep->idx = ssid->wep_tx_keyidx;
238 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 }
240
Dmitry Shmidt04949592012-07-19 12:16:46 -0700241 if (ssid->ap_max_inactivity)
242 bss->ap_max_inactivity = ssid->ap_max_inactivity;
243
244 if (ssid->dtim_period)
245 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800246 else if (wpa_s->conf->dtim_period)
247 bss->dtim_period = wpa_s->conf->dtim_period;
248
249 if (ssid->beacon_int)
250 conf->beacon_int = ssid->beacon_int;
251 else if (wpa_s->conf->beacon_int)
252 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700253
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800254 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
255 bss->rsn_pairwise = bss->wpa_pairwise;
256 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
257 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258
259 if (bss->wpa && bss->ieee802_1x)
260 bss->ssid.security_policy = SECURITY_WPA;
261 else if (bss->wpa)
262 bss->ssid.security_policy = SECURITY_WPA_PSK;
263 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
266 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800267 if (bss->default_wep_key_len)
268 cipher = bss->default_wep_key_len >= 13 ?
269 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
270 bss->wpa_group = cipher;
271 bss->wpa_pairwise = cipher;
272 bss->rsn_pairwise = cipher;
273 } else if (bss->ssid.wep.keys_set) {
274 int cipher = WPA_CIPHER_WEP40;
275 if (bss->ssid.wep.len[0] >= 13)
276 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278 bss->wpa_group = cipher;
279 bss->wpa_pairwise = cipher;
280 bss->rsn_pairwise = cipher;
281 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800283 bss->wpa_group = WPA_CIPHER_NONE;
284 bss->wpa_pairwise = WPA_CIPHER_NONE;
285 bss->rsn_pairwise = WPA_CIPHER_NONE;
286 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700287
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700288 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
289 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800290 bss->wpa_group == WPA_CIPHER_GCMP ||
291 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
292 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700293 /*
294 * Strong ciphers do not need frequent rekeying, so increase
295 * the default GTK rekeying period to 24 hours.
296 */
297 bss->wpa_group_rekey = 86400;
298 }
299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300#ifdef CONFIG_WPS
301 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800302 * Enable WPS by default for open and WPA/WPA2-Personal network, but
303 * require user interaction to actually use it. Only the internal
304 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800306 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
307 bss->ssid.security_policy != SECURITY_PLAINTEXT)
308 goto no_wps;
309#ifdef CONFIG_WPS2
310 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800311 (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800312 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
313 * configuration */
314#endif /* CONFIG_WPS2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700316
317 if (!ssid->ignore_broadcast_ssid)
318 bss->wps_state = 2;
319
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 bss->ap_setup_locked = 2;
321 if (wpa_s->conf->config_methods)
322 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
323 os_memcpy(bss->device_type, wpa_s->conf->device_type,
324 WPS_DEV_TYPE_LEN);
325 if (wpa_s->conf->device_name) {
326 bss->device_name = os_strdup(wpa_s->conf->device_name);
327 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
328 }
329 if (wpa_s->conf->manufacturer)
330 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
331 if (wpa_s->conf->model_name)
332 bss->model_name = os_strdup(wpa_s->conf->model_name);
333 if (wpa_s->conf->model_number)
334 bss->model_number = os_strdup(wpa_s->conf->model_number);
335 if (wpa_s->conf->serial_number)
336 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
337 if (is_nil_uuid(wpa_s->conf->uuid))
338 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
339 else
340 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
341 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700342 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800343no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344#endif /* CONFIG_WPS */
345
346 if (wpa_s->max_stations &&
347 wpa_s->max_stations < wpa_s->conf->max_num_sta)
348 bss->max_num_sta = wpa_s->max_stations;
349 else
350 bss->max_num_sta = wpa_s->conf->max_num_sta;
351
352 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
353
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700354 if (wpa_s->conf->ap_vendor_elements) {
355 bss->vendor_elements =
356 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
357 }
358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 return 0;
360}
361
362
363static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
364{
365#ifdef CONFIG_P2P
366 struct wpa_supplicant *wpa_s = ctx;
367 const struct ieee80211_mgmt *mgmt;
368 size_t hdr_len;
369
370 mgmt = (const struct ieee80211_mgmt *) buf;
371 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
372 if (hdr_len > len)
373 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800374 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
375 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
377 mgmt->u.action.category,
378 &mgmt->u.action.u.vs_public_action.action,
379 len - hdr_len, freq);
380#endif /* CONFIG_P2P */
381}
382
383
384static void ap_wps_event_cb(void *ctx, enum wps_event event,
385 union wps_event_data *data)
386{
387#ifdef CONFIG_P2P
388 struct wpa_supplicant *wpa_s = ctx;
389
Jouni Malinen75ecf522011-06-27 15:19:46 -0700390 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391 struct wps_event_fail *fail = &data->fail;
392
Jouni Malinen75ecf522011-06-27 15:19:46 -0700393 if (wpa_s->parent && wpa_s->parent != wpa_s &&
394 wpa_s == wpa_s->global->p2p_group_formation) {
395 /*
396 * src/ap/wps_hostapd.c has already sent this on the
397 * main interface, so only send on the parent interface
398 * here if needed.
399 */
400 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
401 "msg=%d config_error=%d",
402 fail->msg, fail->config_error);
403 }
404 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 }
406#endif /* CONFIG_P2P */
407}
408
409
410static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800411 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414}
415
416
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700417#ifdef CONFIG_P2P
418static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
419 const u8 *psk, size_t psk_len)
420{
421
422 struct wpa_supplicant *wpa_s = ctx;
423 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
424 return;
425 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
426}
427#endif /* CONFIG_P2P */
428
429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
431{
432#ifdef CONFIG_P2P
433 struct wpa_supplicant *wpa_s = ctx;
434 const struct ieee80211_mgmt *mgmt;
435 size_t hdr_len;
436
437 mgmt = (const struct ieee80211_mgmt *) buf;
438 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
439 if (hdr_len > len)
440 return -1;
441 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
442 mgmt->u.action.category,
443 &mgmt->u.action.u.vs_public_action.action,
444 len - hdr_len, freq);
445#endif /* CONFIG_P2P */
446 return 0;
447}
448
449
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800450static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700451 const u8 *bssid, const u8 *ie, size_t ie_len,
452 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453{
454#ifdef CONFIG_P2P
455 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700456 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
457 ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458#else /* CONFIG_P2P */
459 return 0;
460#endif /* CONFIG_P2P */
461}
462
463
464static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
465 const u8 *uuid_e)
466{
467#ifdef CONFIG_P2P
468 struct wpa_supplicant *wpa_s = ctx;
469 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
470#endif /* CONFIG_P2P */
471}
472
473
474static void wpas_ap_configured_cb(void *ctx)
475{
476 struct wpa_supplicant *wpa_s = ctx;
477
478 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
479
480 if (wpa_s->ap_configured_cb)
481 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
482 wpa_s->ap_configured_cb_data);
483}
484
485
486int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
487 struct wpa_ssid *ssid)
488{
489 struct wpa_driver_associate_params params;
490 struct hostapd_iface *hapd_iface;
491 struct hostapd_config *conf;
492 size_t i;
493
494 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
495 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
496 return -1;
497 }
498
499 wpa_supplicant_ap_deinit(wpa_s);
500
501 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
502 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
503
504 os_memset(&params, 0, sizeof(params));
505 params.ssid = ssid->ssid;
506 params.ssid_len = ssid->ssid_len;
507 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508 case WPAS_MODE_AP:
509 case WPAS_MODE_P2P_GO:
510 case WPAS_MODE_P2P_GROUP_FORMATION:
511 params.mode = IEEE80211_MODE_AP;
512 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800513 default:
514 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700516 if (ssid->frequency == 0)
517 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 params.freq = ssid->frequency;
519
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800520 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
522 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
523 else
524 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800525 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800527 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
528 1);
529 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
531 "cipher.");
532 return -1;
533 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800534 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535 params.group_suite = params.pairwise_suite;
536
537#ifdef CONFIG_P2P
538 if (ssid->mode == WPAS_MODE_P2P_GO ||
539 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
540 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541#endif /* CONFIG_P2P */
542
543 if (wpa_s->parent->set_ap_uapsd)
544 params.uapsd = wpa_s->parent->ap_uapsd;
545 else
546 params.uapsd = -1;
547
548 if (wpa_drv_associate(wpa_s, &params) < 0) {
549 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
550 return -1;
551 }
552
553 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
554 if (hapd_iface == NULL)
555 return -1;
556 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800557 hapd_iface->drv_flags = wpa_s->drv_flags;
558 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700559 hapd_iface->extended_capa = wpa_s->extended_capa;
560 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
561 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562
563 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
564 if (conf == NULL) {
565 wpa_supplicant_ap_deinit(wpa_s);
566 return -1;
567 }
568
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700569 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
570 wpa_s->conf->wmm_ac_params,
571 sizeof(wpa_s->conf->wmm_ac_params));
572
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800573 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800574 conf->bss[0]->wmm_enabled = 1;
575 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800576 }
577
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
579 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
580 wpa_supplicant_ap_deinit(wpa_s);
581 return -1;
582 }
583
584#ifdef CONFIG_P2P
585 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800586 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800588 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 P2P_GROUP_FORMATION;
590#endif /* CONFIG_P2P */
591
592 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700593 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 sizeof(struct hostapd_data *));
595 if (hapd_iface->bss == NULL) {
596 wpa_supplicant_ap_deinit(wpa_s);
597 return -1;
598 }
599
600 for (i = 0; i < conf->num_bss; i++) {
601 hapd_iface->bss[i] =
602 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800603 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604 if (hapd_iface->bss[i] == NULL) {
605 wpa_supplicant_ap_deinit(wpa_s);
606 return -1;
607 }
608
609 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -0700610 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
612 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
613 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
614 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
615 hostapd_register_probereq_cb(hapd_iface->bss[i],
616 ap_probe_req_rx, wpa_s);
617 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
618 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
619 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
620 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
621 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
622 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
623#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700624 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
625 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700627 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
628 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629#endif /* CONFIG_P2P */
630 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
631 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
632 }
633
634 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
635 hapd_iface->bss[0]->driver = wpa_s->driver;
636 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
637
638 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700639 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
641 wpa_s->assoc_freq = ssid->frequency;
642
643 if (hostapd_setup_interface(wpa_s->ap_iface)) {
644 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
645 wpa_supplicant_ap_deinit(wpa_s);
646 return -1;
647 }
648
649 return 0;
650}
651
652
653void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
654{
655#ifdef CONFIG_WPS
656 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
657#endif /* CONFIG_WPS */
658
659 if (wpa_s->ap_iface == NULL)
660 return;
661
662 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700663 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 wpa_s->assoc_freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665#ifdef CONFIG_P2P
666 if (wpa_s->ap_iface->bss)
667 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
668 wpas_p2p_group_deinit(wpa_s);
669#endif /* CONFIG_P2P */
670 hostapd_interface_deinit(wpa_s->ap_iface);
671 hostapd_interface_free(wpa_s->ap_iface);
672 wpa_s->ap_iface = NULL;
673 wpa_drv_deinit_ap(wpa_s);
674}
675
676
677void ap_tx_status(void *ctx, const u8 *addr,
678 const u8 *buf, size_t len, int ack)
679{
680#ifdef NEED_AP_MLME
681 struct wpa_supplicant *wpa_s = ctx;
682 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
683#endif /* NEED_AP_MLME */
684}
685
686
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800687void ap_eapol_tx_status(void *ctx, const u8 *dst,
688 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689{
690#ifdef NEED_AP_MLME
691 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800692 if (!wpa_s->ap_iface)
693 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800694 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
695#endif /* NEED_AP_MLME */
696}
697
698
699void ap_client_poll_ok(void *ctx, const u8 *addr)
700{
701#ifdef NEED_AP_MLME
702 struct wpa_supplicant *wpa_s = ctx;
703 if (wpa_s->ap_iface)
704 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
705#endif /* NEED_AP_MLME */
706}
707
708
709void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
710{
711#ifdef NEED_AP_MLME
712 struct wpa_supplicant *wpa_s = ctx;
713 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714#endif /* NEED_AP_MLME */
715}
716
717
718void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
719{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800720#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 struct wpa_supplicant *wpa_s = ctx;
722 struct hostapd_frame_info fi;
723 os_memset(&fi, 0, sizeof(fi));
724 fi.datarate = rx_mgmt->datarate;
725 fi.ssi_signal = rx_mgmt->ssi_signal;
726 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
727 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800728#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729}
730
731
732void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
733{
734#ifdef NEED_AP_MLME
735 struct wpa_supplicant *wpa_s = ctx;
736 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
737#endif /* NEED_AP_MLME */
738}
739
740
741void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
742 const u8 *src_addr, const u8 *buf, size_t len)
743{
744 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
745}
746
747
748#ifdef CONFIG_WPS
749
750int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
751 const u8 *p2p_dev_addr)
752{
753 if (!wpa_s->ap_iface)
754 return -1;
755 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
756 p2p_dev_addr);
757}
758
759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
761{
762 struct wps_registrar *reg;
763 int reg_sel = 0, wps_sta = 0;
764
765 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
766 return -1;
767
768 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
769 reg_sel = wps_registrar_wps_cancel(reg);
770 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700771 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772
773 if (!reg_sel && !wps_sta) {
774 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
775 "time");
776 return -1;
777 }
778
779 /*
780 * There are 2 cases to return wps cancel as success:
781 * 1. When wps cancel was initiated but no connection has been
782 * established with client yet.
783 * 2. Client is in the middle of exchanging WPS messages.
784 */
785
786 return 0;
787}
788
789
790int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800791 const char *pin, char *buf, size_t buflen,
792 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793{
794 int ret, ret_len = 0;
795
796 if (!wpa_s->ap_iface)
797 return -1;
798
799 if (pin == NULL) {
800 unsigned int rpin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800801 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 pin = buf;
803 } else
804 ret_len = os_snprintf(buf, buflen, "%s", pin);
805
806 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800807 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 if (ret)
809 return -1;
810 return ret_len;
811}
812
813
814static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
815{
816 struct wpa_supplicant *wpa_s = eloop_data;
817 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
818 wpas_wps_ap_pin_disable(wpa_s);
819}
820
821
822static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
823{
824 struct hostapd_data *hapd;
825
826 if (wpa_s->ap_iface == NULL)
827 return;
828 hapd = wpa_s->ap_iface->bss[0];
829 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
830 hapd->ap_pin_failures = 0;
831 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
832 if (timeout > 0)
833 eloop_register_timeout(timeout, 0,
834 wpas_wps_ap_pin_timeout, wpa_s, NULL);
835}
836
837
838void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
839{
840 struct hostapd_data *hapd;
841
842 if (wpa_s->ap_iface == NULL)
843 return;
844 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
845 hapd = wpa_s->ap_iface->bss[0];
846 os_free(hapd->conf->ap_pin);
847 hapd->conf->ap_pin = NULL;
848 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
849}
850
851
852const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
853{
854 struct hostapd_data *hapd;
855 unsigned int pin;
856 char pin_txt[9];
857
858 if (wpa_s->ap_iface == NULL)
859 return NULL;
860 hapd = wpa_s->ap_iface->bss[0];
861 pin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 os_free(hapd->conf->ap_pin);
864 hapd->conf->ap_pin = os_strdup(pin_txt);
865 if (hapd->conf->ap_pin == NULL)
866 return NULL;
867 wpas_wps_ap_pin_enable(wpa_s, timeout);
868
869 return hapd->conf->ap_pin;
870}
871
872
873const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
874{
875 struct hostapd_data *hapd;
876 if (wpa_s->ap_iface == NULL)
877 return NULL;
878 hapd = wpa_s->ap_iface->bss[0];
879 return hapd->conf->ap_pin;
880}
881
882
883int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
884 int timeout)
885{
886 struct hostapd_data *hapd;
887 char pin_txt[9];
888 int ret;
889
890 if (wpa_s->ap_iface == NULL)
891 return -1;
892 hapd = wpa_s->ap_iface->bss[0];
893 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
894 if (ret < 0 || ret >= (int) sizeof(pin_txt))
895 return -1;
896 os_free(hapd->conf->ap_pin);
897 hapd->conf->ap_pin = os_strdup(pin_txt);
898 if (hapd->conf->ap_pin == NULL)
899 return -1;
900 wpas_wps_ap_pin_enable(wpa_s, timeout);
901
902 return 0;
903}
904
905
906void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
907{
908 struct hostapd_data *hapd;
909
910 if (wpa_s->ap_iface == NULL)
911 return;
912 hapd = wpa_s->ap_iface->bss[0];
913
914 /*
915 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
916 * PIN if this happens multiple times to slow down brute force attacks.
917 */
918 hapd->ap_pin_failures++;
919 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
920 hapd->ap_pin_failures);
921 if (hapd->ap_pin_failures < 3)
922 return;
923
924 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
925 hapd->ap_pin_failures = 0;
926 os_free(hapd->conf->ap_pin);
927 hapd->conf->ap_pin = NULL;
928}
929
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800930
931#ifdef CONFIG_WPS_NFC
932
933struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
934 int ndef)
935{
936 struct hostapd_data *hapd;
937
938 if (wpa_s->ap_iface == NULL)
939 return NULL;
940 hapd = wpa_s->ap_iface->bss[0];
941 return hostapd_wps_nfc_config_token(hapd, ndef);
942}
943
944
945struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
946 int ndef)
947{
948 struct hostapd_data *hapd;
949
950 if (wpa_s->ap_iface == NULL)
951 return NULL;
952 hapd = wpa_s->ap_iface->bss[0];
953 return hostapd_wps_nfc_hs_cr(hapd, ndef);
954}
955
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800956
957int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
958 const struct wpabuf *req,
959 const struct wpabuf *sel)
960{
961 struct hostapd_data *hapd;
962
963 if (wpa_s->ap_iface == NULL)
964 return -1;
965 hapd = wpa_s->ap_iface->bss[0];
966 return hostapd_wps_nfc_report_handover(hapd, req, sel);
967}
968
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800969#endif /* CONFIG_WPS_NFC */
970
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971#endif /* CONFIG_WPS */
972
973
974#ifdef CONFIG_CTRL_IFACE
975
976int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
977 char *buf, size_t buflen)
978{
979 if (wpa_s->ap_iface == NULL)
980 return -1;
981 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
982 buf, buflen);
983}
984
985
986int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
987 char *buf, size_t buflen)
988{
989 if (wpa_s->ap_iface == NULL)
990 return -1;
991 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
992 buf, buflen);
993}
994
995
996int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
997 char *buf, size_t buflen)
998{
999 if (wpa_s->ap_iface == NULL)
1000 return -1;
1001 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
1002 buf, buflen);
1003}
1004
1005
Dmitry Shmidt04949592012-07-19 12:16:46 -07001006int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1007 const char *txtaddr)
1008{
1009 if (wpa_s->ap_iface == NULL)
1010 return -1;
1011 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1012 txtaddr);
1013}
1014
1015
1016int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1017 const char *txtaddr)
1018{
1019 if (wpa_s->ap_iface == NULL)
1020 return -1;
1021 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1022 txtaddr);
1023}
1024
1025
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1027 size_t buflen, int verbose)
1028{
1029 char *pos = buf, *end = buf + buflen;
1030 int ret;
1031 struct hostapd_bss_config *conf;
1032
1033 if (wpa_s->ap_iface == NULL)
1034 return -1;
1035
1036 conf = wpa_s->ap_iface->bss[0]->conf;
1037 if (conf->wpa == 0)
1038 return 0;
1039
1040 ret = os_snprintf(pos, end - pos,
1041 "pairwise_cipher=%s\n"
1042 "group_cipher=%s\n"
1043 "key_mgmt=%s\n",
1044 wpa_cipher_txt(conf->rsn_pairwise),
1045 wpa_cipher_txt(conf->wpa_group),
1046 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1047 conf->wpa));
1048 if (ret < 0 || ret >= end - pos)
1049 return pos - buf;
1050 pos += ret;
1051 return pos - buf;
1052}
1053
1054#endif /* CONFIG_CTRL_IFACE */
1055
1056
1057int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1058{
1059 struct hostapd_iface *iface = wpa_s->ap_iface;
1060 struct wpa_ssid *ssid = wpa_s->current_ssid;
1061 struct hostapd_data *hapd;
1062
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001063 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1064 ssid->mode == WPAS_MODE_INFRA ||
1065 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066 return -1;
1067
1068#ifdef CONFIG_P2P
1069 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001070 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001072 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 P2P_GROUP_FORMATION;
1074#endif /* CONFIG_P2P */
1075
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001077 if (hapd->drv_priv == NULL)
1078 return -1;
1079 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 hostapd_set_ap_wps_ie(hapd);
1081
1082 return 0;
1083}
1084
1085
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001086int ap_switch_channel(struct wpa_supplicant *wpa_s,
1087 struct csa_settings *settings)
1088{
1089#ifdef NEED_AP_MLME
1090 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1091 return -1;
1092
1093 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1094#else /* NEED_AP_MLME */
1095 return -1;
1096#endif /* NEED_AP_MLME */
1097}
1098
1099
1100int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1101{
1102 struct csa_settings settings;
1103 int ret = hostapd_parse_csa_settings(pos, &settings);
1104
1105 if (ret)
1106 return ret;
1107
1108 return ap_switch_channel(wpa_s, &settings);
1109}
1110
1111
Dmitry Shmidt04949592012-07-19 12:16:46 -07001112void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001113 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001114{
1115 if (!wpa_s->ap_iface)
1116 return;
1117
1118 wpa_s->assoc_freq = freq;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001119 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001120}
1121
1122
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1124 const u8 *addr)
1125{
1126 struct hostapd_data *hapd;
1127 struct hostapd_bss_config *conf;
1128
1129 if (!wpa_s->ap_iface)
1130 return -1;
1131
1132 if (addr)
1133 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1134 MAC2STR(addr));
1135 else
1136 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1137
1138 hapd = wpa_s->ap_iface->bss[0];
1139 conf = hapd->conf;
1140
1141 os_free(conf->accept_mac);
1142 conf->accept_mac = NULL;
1143 conf->num_accept_mac = 0;
1144 os_free(conf->deny_mac);
1145 conf->deny_mac = NULL;
1146 conf->num_deny_mac = 0;
1147
1148 if (addr == NULL) {
1149 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1150 return 0;
1151 }
1152
1153 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1154 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1155 if (conf->accept_mac == NULL)
1156 return -1;
1157 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1158 conf->num_accept_mac = 1;
1159
1160 return 0;
1161}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001162
1163
1164#ifdef CONFIG_WPS_NFC
1165int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1166 const struct wpabuf *pw, const u8 *pubkey_hash)
1167{
1168 struct hostapd_data *hapd;
1169 struct wps_context *wps;
1170
1171 if (!wpa_s->ap_iface)
1172 return -1;
1173 hapd = wpa_s->ap_iface->bss[0];
1174 wps = hapd->wps;
1175
1176 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1177 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1178 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1179 return -1;
1180 }
1181
1182 dh5_free(wps->dh_ctx);
1183 wpabuf_free(wps->dh_pubkey);
1184 wpabuf_free(wps->dh_privkey);
1185 wps->dh_privkey = wpabuf_dup(
1186 wpa_s->parent->conf->wps_nfc_dh_privkey);
1187 wps->dh_pubkey = wpabuf_dup(
1188 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1189 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1190 wps->dh_ctx = NULL;
1191 wpabuf_free(wps->dh_pubkey);
1192 wps->dh_pubkey = NULL;
1193 wpabuf_free(wps->dh_privkey);
1194 wps->dh_privkey = NULL;
1195 return -1;
1196 }
1197 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1198 if (wps->dh_ctx == NULL)
1199 return -1;
1200
1201 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1202 pw_id,
1203 pw ? wpabuf_head(pw) : NULL,
1204 pw ? wpabuf_len(pw) : 0, 1);
1205}
1206#endif /* CONFIG_WPS_NFC */