blob: e7d59de99f1ccd928c712b27515fb6ce8c83b823 [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 Shmidtb36ed7c2014-03-17 10:57:26 -0700300#ifdef CONFIG_IEEE80211W
301 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
302 bss->ieee80211w = ssid->ieee80211w;
303#endif /* CONFIG_IEEE80211W */
304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305#ifdef CONFIG_WPS
306 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800307 * Enable WPS by default for open and WPA/WPA2-Personal network, but
308 * require user interaction to actually use it. Only the internal
309 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800311 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
312 bss->ssid.security_policy != SECURITY_PLAINTEXT)
313 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800314 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800315 (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800316 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
317 * configuration */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700319
320 if (!ssid->ignore_broadcast_ssid)
321 bss->wps_state = 2;
322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323 bss->ap_setup_locked = 2;
324 if (wpa_s->conf->config_methods)
325 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
326 os_memcpy(bss->device_type, wpa_s->conf->device_type,
327 WPS_DEV_TYPE_LEN);
328 if (wpa_s->conf->device_name) {
329 bss->device_name = os_strdup(wpa_s->conf->device_name);
330 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
331 }
332 if (wpa_s->conf->manufacturer)
333 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
334 if (wpa_s->conf->model_name)
335 bss->model_name = os_strdup(wpa_s->conf->model_name);
336 if (wpa_s->conf->model_number)
337 bss->model_number = os_strdup(wpa_s->conf->model_number);
338 if (wpa_s->conf->serial_number)
339 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
340 if (is_nil_uuid(wpa_s->conf->uuid))
341 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
342 else
343 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
344 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700345 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800346no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347#endif /* CONFIG_WPS */
348
349 if (wpa_s->max_stations &&
350 wpa_s->max_stations < wpa_s->conf->max_num_sta)
351 bss->max_num_sta = wpa_s->max_stations;
352 else
353 bss->max_num_sta = wpa_s->conf->max_num_sta;
354
355 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
356
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700357 if (wpa_s->conf->ap_vendor_elements) {
358 bss->vendor_elements =
359 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
360 }
361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362 return 0;
363}
364
365
366static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
367{
368#ifdef CONFIG_P2P
369 struct wpa_supplicant *wpa_s = ctx;
370 const struct ieee80211_mgmt *mgmt;
371 size_t hdr_len;
372
373 mgmt = (const struct ieee80211_mgmt *) buf;
374 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
375 if (hdr_len > len)
376 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800377 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
378 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
380 mgmt->u.action.category,
381 &mgmt->u.action.u.vs_public_action.action,
382 len - hdr_len, freq);
383#endif /* CONFIG_P2P */
384}
385
386
387static void ap_wps_event_cb(void *ctx, enum wps_event event,
388 union wps_event_data *data)
389{
390#ifdef CONFIG_P2P
391 struct wpa_supplicant *wpa_s = ctx;
392
Jouni Malinen75ecf522011-06-27 15:19:46 -0700393 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394 struct wps_event_fail *fail = &data->fail;
395
Jouni Malinen75ecf522011-06-27 15:19:46 -0700396 if (wpa_s->parent && wpa_s->parent != wpa_s &&
397 wpa_s == wpa_s->global->p2p_group_formation) {
398 /*
399 * src/ap/wps_hostapd.c has already sent this on the
400 * main interface, so only send on the parent interface
401 * here if needed.
402 */
403 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
404 "msg=%d config_error=%d",
405 fail->msg, fail->config_error);
406 }
407 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408 }
409#endif /* CONFIG_P2P */
410}
411
412
413static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800414 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417}
418
419
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700420#ifdef CONFIG_P2P
421static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
422 const u8 *psk, size_t psk_len)
423{
424
425 struct wpa_supplicant *wpa_s = ctx;
426 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
427 return;
428 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
429}
430#endif /* CONFIG_P2P */
431
432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
434{
435#ifdef CONFIG_P2P
436 struct wpa_supplicant *wpa_s = ctx;
437 const struct ieee80211_mgmt *mgmt;
438 size_t hdr_len;
439
440 mgmt = (const struct ieee80211_mgmt *) buf;
441 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
442 if (hdr_len > len)
443 return -1;
444 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
445 mgmt->u.action.category,
446 &mgmt->u.action.u.vs_public_action.action,
447 len - hdr_len, freq);
448#endif /* CONFIG_P2P */
449 return 0;
450}
451
452
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800453static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700454 const u8 *bssid, const u8 *ie, size_t ie_len,
455 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456{
457#ifdef CONFIG_P2P
458 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700459 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
460 ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461#else /* CONFIG_P2P */
462 return 0;
463#endif /* CONFIG_P2P */
464}
465
466
467static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
468 const u8 *uuid_e)
469{
470#ifdef CONFIG_P2P
471 struct wpa_supplicant *wpa_s = ctx;
472 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
473#endif /* CONFIG_P2P */
474}
475
476
477static void wpas_ap_configured_cb(void *ctx)
478{
479 struct wpa_supplicant *wpa_s = ctx;
480
481 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
482
483 if (wpa_s->ap_configured_cb)
484 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
485 wpa_s->ap_configured_cb_data);
486}
487
488
489int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
490 struct wpa_ssid *ssid)
491{
492 struct wpa_driver_associate_params params;
493 struct hostapd_iface *hapd_iface;
494 struct hostapd_config *conf;
495 size_t i;
496
497 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
498 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
499 return -1;
500 }
501
502 wpa_supplicant_ap_deinit(wpa_s);
503
504 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
505 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
506
507 os_memset(&params, 0, sizeof(params));
508 params.ssid = ssid->ssid;
509 params.ssid_len = ssid->ssid_len;
510 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 case WPAS_MODE_AP:
512 case WPAS_MODE_P2P_GO:
513 case WPAS_MODE_P2P_GROUP_FORMATION:
514 params.mode = IEEE80211_MODE_AP;
515 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800516 default:
517 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700519 if (ssid->frequency == 0)
520 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 params.freq = ssid->frequency;
522
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800523 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700524 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
525 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
526 else
527 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800528 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800530 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
531 1);
532 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700533 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
534 "cipher.");
535 return -1;
536 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800537 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 params.group_suite = params.pairwise_suite;
539
540#ifdef CONFIG_P2P
541 if (ssid->mode == WPAS_MODE_P2P_GO ||
542 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
543 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544#endif /* CONFIG_P2P */
545
546 if (wpa_s->parent->set_ap_uapsd)
547 params.uapsd = wpa_s->parent->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800548 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
549 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550 else
551 params.uapsd = -1;
552
553 if (wpa_drv_associate(wpa_s, &params) < 0) {
554 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
555 return -1;
556 }
557
558 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
559 if (hapd_iface == NULL)
560 return -1;
561 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800562 hapd_iface->drv_flags = wpa_s->drv_flags;
563 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700564 hapd_iface->extended_capa = wpa_s->extended_capa;
565 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
566 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567
568 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
569 if (conf == NULL) {
570 wpa_supplicant_ap_deinit(wpa_s);
571 return -1;
572 }
573
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700574 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
575 wpa_s->conf->wmm_ac_params,
576 sizeof(wpa_s->conf->wmm_ac_params));
577
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800578 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800579 conf->bss[0]->wmm_enabled = 1;
580 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800581 }
582
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700583 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
584 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
585 wpa_supplicant_ap_deinit(wpa_s);
586 return -1;
587 }
588
589#ifdef CONFIG_P2P
590 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800591 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800593 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 P2P_GROUP_FORMATION;
595#endif /* CONFIG_P2P */
596
597 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700598 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599 sizeof(struct hostapd_data *));
600 if (hapd_iface->bss == NULL) {
601 wpa_supplicant_ap_deinit(wpa_s);
602 return -1;
603 }
604
605 for (i = 0; i < conf->num_bss; i++) {
606 hapd_iface->bss[i] =
607 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800608 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 if (hapd_iface->bss[i] == NULL) {
610 wpa_supplicant_ap_deinit(wpa_s);
611 return -1;
612 }
613
614 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -0700615 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
617 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
618 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
619 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
620 hostapd_register_probereq_cb(hapd_iface->bss[i],
621 ap_probe_req_rx, wpa_s);
622 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
623 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
624 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
625 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
626 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
627 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
628#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700629 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
630 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700632 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
633 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700634#endif /* CONFIG_P2P */
635 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
636 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
637 }
638
639 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
640 hapd_iface->bss[0]->driver = wpa_s->driver;
641 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
642
643 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700644 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
646 wpa_s->assoc_freq = ssid->frequency;
647
648 if (hostapd_setup_interface(wpa_s->ap_iface)) {
649 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
650 wpa_supplicant_ap_deinit(wpa_s);
651 return -1;
652 }
653
654 return 0;
655}
656
657
658void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
659{
660#ifdef CONFIG_WPS
661 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
662#endif /* CONFIG_WPS */
663
664 if (wpa_s->ap_iface == NULL)
665 return;
666
667 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700668 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669 wpa_s->assoc_freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670#ifdef CONFIG_P2P
671 if (wpa_s->ap_iface->bss)
672 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
673 wpas_p2p_group_deinit(wpa_s);
674#endif /* CONFIG_P2P */
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800675 wpa_s->ap_iface->driver_ap_teardown =
676 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 hostapd_interface_deinit(wpa_s->ap_iface);
679 hostapd_interface_free(wpa_s->ap_iface);
680 wpa_s->ap_iface = NULL;
681 wpa_drv_deinit_ap(wpa_s);
682}
683
684
685void ap_tx_status(void *ctx, const u8 *addr,
686 const u8 *buf, size_t len, int ack)
687{
688#ifdef NEED_AP_MLME
689 struct wpa_supplicant *wpa_s = ctx;
690 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
691#endif /* NEED_AP_MLME */
692}
693
694
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800695void ap_eapol_tx_status(void *ctx, const u8 *dst,
696 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700697{
698#ifdef NEED_AP_MLME
699 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800700 if (!wpa_s->ap_iface)
701 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800702 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
703#endif /* NEED_AP_MLME */
704}
705
706
707void ap_client_poll_ok(void *ctx, const u8 *addr)
708{
709#ifdef NEED_AP_MLME
710 struct wpa_supplicant *wpa_s = ctx;
711 if (wpa_s->ap_iface)
712 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
713#endif /* NEED_AP_MLME */
714}
715
716
717void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
718{
719#ifdef NEED_AP_MLME
720 struct wpa_supplicant *wpa_s = ctx;
721 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722#endif /* NEED_AP_MLME */
723}
724
725
726void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
727{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800728#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 struct wpa_supplicant *wpa_s = ctx;
730 struct hostapd_frame_info fi;
731 os_memset(&fi, 0, sizeof(fi));
732 fi.datarate = rx_mgmt->datarate;
733 fi.ssi_signal = rx_mgmt->ssi_signal;
734 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
735 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800736#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737}
738
739
740void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
741{
742#ifdef NEED_AP_MLME
743 struct wpa_supplicant *wpa_s = ctx;
744 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
745#endif /* NEED_AP_MLME */
746}
747
748
749void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
750 const u8 *src_addr, const u8 *buf, size_t len)
751{
752 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
753}
754
755
756#ifdef CONFIG_WPS
757
758int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
759 const u8 *p2p_dev_addr)
760{
761 if (!wpa_s->ap_iface)
762 return -1;
763 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
764 p2p_dev_addr);
765}
766
767
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
769{
770 struct wps_registrar *reg;
771 int reg_sel = 0, wps_sta = 0;
772
773 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
774 return -1;
775
776 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
777 reg_sel = wps_registrar_wps_cancel(reg);
778 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700779 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780
781 if (!reg_sel && !wps_sta) {
782 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
783 "time");
784 return -1;
785 }
786
787 /*
788 * There are 2 cases to return wps cancel as success:
789 * 1. When wps cancel was initiated but no connection has been
790 * established with client yet.
791 * 2. Client is in the middle of exchanging WPS messages.
792 */
793
794 return 0;
795}
796
797
798int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800799 const char *pin, char *buf, size_t buflen,
800 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801{
802 int ret, ret_len = 0;
803
804 if (!wpa_s->ap_iface)
805 return -1;
806
807 if (pin == NULL) {
808 unsigned int rpin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800809 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 pin = buf;
811 } else
812 ret_len = os_snprintf(buf, buflen, "%s", pin);
813
814 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800815 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816 if (ret)
817 return -1;
818 return ret_len;
819}
820
821
822static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
823{
824 struct wpa_supplicant *wpa_s = eloop_data;
825 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
826 wpas_wps_ap_pin_disable(wpa_s);
827}
828
829
830static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
831{
832 struct hostapd_data *hapd;
833
834 if (wpa_s->ap_iface == NULL)
835 return;
836 hapd = wpa_s->ap_iface->bss[0];
837 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
838 hapd->ap_pin_failures = 0;
839 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
840 if (timeout > 0)
841 eloop_register_timeout(timeout, 0,
842 wpas_wps_ap_pin_timeout, wpa_s, NULL);
843}
844
845
846void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
847{
848 struct hostapd_data *hapd;
849
850 if (wpa_s->ap_iface == NULL)
851 return;
852 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
853 hapd = wpa_s->ap_iface->bss[0];
854 os_free(hapd->conf->ap_pin);
855 hapd->conf->ap_pin = NULL;
856 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
857}
858
859
860const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
861{
862 struct hostapd_data *hapd;
863 unsigned int pin;
864 char pin_txt[9];
865
866 if (wpa_s->ap_iface == NULL)
867 return NULL;
868 hapd = wpa_s->ap_iface->bss[0];
869 pin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800870 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871 os_free(hapd->conf->ap_pin);
872 hapd->conf->ap_pin = os_strdup(pin_txt);
873 if (hapd->conf->ap_pin == NULL)
874 return NULL;
875 wpas_wps_ap_pin_enable(wpa_s, timeout);
876
877 return hapd->conf->ap_pin;
878}
879
880
881const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
882{
883 struct hostapd_data *hapd;
884 if (wpa_s->ap_iface == NULL)
885 return NULL;
886 hapd = wpa_s->ap_iface->bss[0];
887 return hapd->conf->ap_pin;
888}
889
890
891int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
892 int timeout)
893{
894 struct hostapd_data *hapd;
895 char pin_txt[9];
896 int ret;
897
898 if (wpa_s->ap_iface == NULL)
899 return -1;
900 hapd = wpa_s->ap_iface->bss[0];
901 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
902 if (ret < 0 || ret >= (int) sizeof(pin_txt))
903 return -1;
904 os_free(hapd->conf->ap_pin);
905 hapd->conf->ap_pin = os_strdup(pin_txt);
906 if (hapd->conf->ap_pin == NULL)
907 return -1;
908 wpas_wps_ap_pin_enable(wpa_s, timeout);
909
910 return 0;
911}
912
913
914void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
915{
916 struct hostapd_data *hapd;
917
918 if (wpa_s->ap_iface == NULL)
919 return;
920 hapd = wpa_s->ap_iface->bss[0];
921
922 /*
923 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
924 * PIN if this happens multiple times to slow down brute force attacks.
925 */
926 hapd->ap_pin_failures++;
927 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
928 hapd->ap_pin_failures);
929 if (hapd->ap_pin_failures < 3)
930 return;
931
932 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
933 hapd->ap_pin_failures = 0;
934 os_free(hapd->conf->ap_pin);
935 hapd->conf->ap_pin = NULL;
936}
937
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800938
939#ifdef CONFIG_WPS_NFC
940
941struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
942 int ndef)
943{
944 struct hostapd_data *hapd;
945
946 if (wpa_s->ap_iface == NULL)
947 return NULL;
948 hapd = wpa_s->ap_iface->bss[0];
949 return hostapd_wps_nfc_config_token(hapd, ndef);
950}
951
952
953struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
954 int ndef)
955{
956 struct hostapd_data *hapd;
957
958 if (wpa_s->ap_iface == NULL)
959 return NULL;
960 hapd = wpa_s->ap_iface->bss[0];
961 return hostapd_wps_nfc_hs_cr(hapd, ndef);
962}
963
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800964
965int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
966 const struct wpabuf *req,
967 const struct wpabuf *sel)
968{
969 struct hostapd_data *hapd;
970
971 if (wpa_s->ap_iface == NULL)
972 return -1;
973 hapd = wpa_s->ap_iface->bss[0];
974 return hostapd_wps_nfc_report_handover(hapd, req, sel);
975}
976
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800977#endif /* CONFIG_WPS_NFC */
978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700979#endif /* CONFIG_WPS */
980
981
982#ifdef CONFIG_CTRL_IFACE
983
984int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
985 char *buf, size_t buflen)
986{
987 if (wpa_s->ap_iface == NULL)
988 return -1;
989 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
990 buf, buflen);
991}
992
993
994int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
995 char *buf, size_t buflen)
996{
997 if (wpa_s->ap_iface == NULL)
998 return -1;
999 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
1000 buf, buflen);
1001}
1002
1003
1004int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1005 char *buf, size_t buflen)
1006{
1007 if (wpa_s->ap_iface == NULL)
1008 return -1;
1009 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
1010 buf, buflen);
1011}
1012
1013
Dmitry Shmidt04949592012-07-19 12:16:46 -07001014int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1015 const char *txtaddr)
1016{
1017 if (wpa_s->ap_iface == NULL)
1018 return -1;
1019 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1020 txtaddr);
1021}
1022
1023
1024int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1025 const char *txtaddr)
1026{
1027 if (wpa_s->ap_iface == NULL)
1028 return -1;
1029 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1030 txtaddr);
1031}
1032
1033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1035 size_t buflen, int verbose)
1036{
1037 char *pos = buf, *end = buf + buflen;
1038 int ret;
1039 struct hostapd_bss_config *conf;
1040
1041 if (wpa_s->ap_iface == NULL)
1042 return -1;
1043
1044 conf = wpa_s->ap_iface->bss[0]->conf;
1045 if (conf->wpa == 0)
1046 return 0;
1047
1048 ret = os_snprintf(pos, end - pos,
1049 "pairwise_cipher=%s\n"
1050 "group_cipher=%s\n"
1051 "key_mgmt=%s\n",
1052 wpa_cipher_txt(conf->rsn_pairwise),
1053 wpa_cipher_txt(conf->wpa_group),
1054 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1055 conf->wpa));
1056 if (ret < 0 || ret >= end - pos)
1057 return pos - buf;
1058 pos += ret;
1059 return pos - buf;
1060}
1061
1062#endif /* CONFIG_CTRL_IFACE */
1063
1064
1065int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1066{
1067 struct hostapd_iface *iface = wpa_s->ap_iface;
1068 struct wpa_ssid *ssid = wpa_s->current_ssid;
1069 struct hostapd_data *hapd;
1070
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001071 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1072 ssid->mode == WPAS_MODE_INFRA ||
1073 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074 return -1;
1075
1076#ifdef CONFIG_P2P
1077 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001078 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001080 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 P2P_GROUP_FORMATION;
1082#endif /* CONFIG_P2P */
1083
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001085 if (hapd->drv_priv == NULL)
1086 return -1;
1087 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 hostapd_set_ap_wps_ie(hapd);
1089
1090 return 0;
1091}
1092
1093
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001094int ap_switch_channel(struct wpa_supplicant *wpa_s,
1095 struct csa_settings *settings)
1096{
1097#ifdef NEED_AP_MLME
1098 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1099 return -1;
1100
1101 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1102#else /* NEED_AP_MLME */
1103 return -1;
1104#endif /* NEED_AP_MLME */
1105}
1106
1107
1108int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1109{
1110 struct csa_settings settings;
1111 int ret = hostapd_parse_csa_settings(pos, &settings);
1112
1113 if (ret)
1114 return ret;
1115
1116 return ap_switch_channel(wpa_s, &settings);
1117}
1118
1119
Dmitry Shmidt04949592012-07-19 12:16:46 -07001120void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001121 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001122{
1123 if (!wpa_s->ap_iface)
1124 return;
1125
1126 wpa_s->assoc_freq = freq;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001127 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001128}
1129
1130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1132 const u8 *addr)
1133{
1134 struct hostapd_data *hapd;
1135 struct hostapd_bss_config *conf;
1136
1137 if (!wpa_s->ap_iface)
1138 return -1;
1139
1140 if (addr)
1141 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1142 MAC2STR(addr));
1143 else
1144 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1145
1146 hapd = wpa_s->ap_iface->bss[0];
1147 conf = hapd->conf;
1148
1149 os_free(conf->accept_mac);
1150 conf->accept_mac = NULL;
1151 conf->num_accept_mac = 0;
1152 os_free(conf->deny_mac);
1153 conf->deny_mac = NULL;
1154 conf->num_deny_mac = 0;
1155
1156 if (addr == NULL) {
1157 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1158 return 0;
1159 }
1160
1161 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1162 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1163 if (conf->accept_mac == NULL)
1164 return -1;
1165 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1166 conf->num_accept_mac = 1;
1167
1168 return 0;
1169}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001170
1171
1172#ifdef CONFIG_WPS_NFC
1173int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1174 const struct wpabuf *pw, const u8 *pubkey_hash)
1175{
1176 struct hostapd_data *hapd;
1177 struct wps_context *wps;
1178
1179 if (!wpa_s->ap_iface)
1180 return -1;
1181 hapd = wpa_s->ap_iface->bss[0];
1182 wps = hapd->wps;
1183
1184 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1185 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1186 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1187 return -1;
1188 }
1189
1190 dh5_free(wps->dh_ctx);
1191 wpabuf_free(wps->dh_pubkey);
1192 wpabuf_free(wps->dh_privkey);
1193 wps->dh_privkey = wpabuf_dup(
1194 wpa_s->parent->conf->wps_nfc_dh_privkey);
1195 wps->dh_pubkey = wpabuf_dup(
1196 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1197 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1198 wps->dh_ctx = NULL;
1199 wpabuf_free(wps->dh_pubkey);
1200 wps->dh_pubkey = NULL;
1201 wpabuf_free(wps->dh_privkey);
1202 wps->dh_privkey = NULL;
1203 return -1;
1204 }
1205 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1206 if (wps->dh_ctx == NULL)
1207 return -1;
1208
1209 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1210 pw_id,
1211 pw ? wpabuf_head(pw) : NULL,
1212 pw ? wpabuf_len(pw) : 0, 1);
1213}
1214#endif /* CONFIG_WPS_NFC */