]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/ap.c
WPS: Remove unused Credential AP Channel processing
[thirdparty/hostap.git] / wpa_supplicant / ap.c
CommitLineData
f1a48710
JM
1/*
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 *
0f3d578e
JM
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
f1a48710
JM
8 */
9
6226e38d 10#include "utils/includes.h"
f1a48710 11
6226e38d 12#include "utils/common.h"
70d84f11 13#include "utils/eloop.h"
ab45223b 14#include "utils/uuid.h"
58c26600 15#include "common/ieee802_11_defs.h"
a0dee797 16#include "common/wpa_ctrl.h"
25a8f9e3 17#include "eapol_supp/eapol_supp_sm.h"
db6ae69e 18#include "crypto/dh_group5.h"
1057d78e 19#include "ap/hostapd.h"
6226e38d 20#include "ap/ap_config.h"
fe99fb74 21#include "ap/ap_drv_ops.h"
fe6bdb77 22#ifdef NEED_AP_MLME
1057d78e 23#include "ap/ieee802_11.h"
fe6bdb77 24#endif /* NEED_AP_MLME */
b22128ef 25#include "ap/beacon.h"
a8e0505b 26#include "ap/ieee802_1x.h"
363b9e60 27#include "ap/wps_hostapd.h"
0e2d35c6 28#include "ap/ctrl_iface_ap.h"
3ec97afe 29#include "wps/wps.h"
e44f8bf2 30#include "common/ieee802_11_defs.h"
1f1b62a0 31#include "config_ssid.h"
094393b1 32#include "config.h"
1f1b62a0 33#include "wpa_supplicant_i.h"
2d5b792d 34#include "driver_i.h"
e44f8bf2 35#include "p2p_supplicant.h"
2d5b792d 36#include "ap.h"
2f9929ff 37#include "ap/sta_info.h"
d8a43924 38#include "notify.h"
f1a48710
JM
39
40
0fe620de 41#ifdef CONFIG_WPS
70d84f11 42static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
0fe620de 43#endif /* CONFIG_WPS */
70d84f11
JM
44
45
c20bc9d4 46#ifdef CONFIG_IEEE80211N
ca9bc5b5
EP
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}
c20bc9d4 70#endif /* CONFIG_IEEE80211N */
ca9bc5b5
EP
71
72
07f117ed
JM
73static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
74 struct wpa_ssid *ssid,
75 struct hostapd_config *conf)
76{
ebd79f07 77 struct hostapd_bss_config *bss = conf->bss[0];
c5121837 78
a911a6e6 79 conf->driver = wpa_s->driver;
07f117ed
JM
80
81 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
82
973622cd
AS
83 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;
07f117ed
JM
89 }
90
2db91745 91 /* TODO: enable HT40 if driver supports it;
07f117ed
JM
92 * drop to 11b if driver does not support 11g */
93
2db91745
AC
94#ifdef CONFIG_IEEE80211N
95 /*
79b8c60f
AN
96 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
97 * and a mask of allowed capabilities within conf->ht_capab.
2db91745 98 * Using default config settings for: conf->ht_op_mode_fixed,
79b8c60f 99 * conf->secondary_channel, conf->require_ht
2db91745 100 */
6bf731e8 101 if (wpa_s->hw.modes) {
2db91745 102 struct hostapd_hw_modes *mode = NULL;
5cbf5fd9 103 int i, no_ht = 0;
6bf731e8
CL
104 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];
2db91745
AC
107 break;
108 }
109 }
5cbf5fd9
VT
110
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) {
2db91745 120 conf->ieee80211n = 1;
7aeac985
RM
121#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 */
79b8c60f
AN
133
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);
ca9bc5b5
EP
145
146 if (mode->vht_capab && ssid->vht) {
147 conf->ieee80211ac = 1;
148 wpas_conf_ap_vht(wpa_s, conf, mode);
149 }
79b8c60f 150 }
2db91745
AC
151 }
152#endif /* CONFIG_IEEE80211N */
153
4c2c3028 154#ifdef CONFIG_P2P
1e0e943e
AB
155 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
156 (ssid->mode == WPAS_MODE_P2P_GO ||
157 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
4c2c3028
JM
158 /* 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 }
6cd930cb
JB
182
183 bss->isolate = !wpa_s->conf->p2p_intra_bss;
05766ed8 184 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
25ef8529
JM
185
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 }
4c2c3028
JM
195#endif /* CONFIG_P2P */
196
07f117ed
JM
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);
07f117ed
JM
202 bss->ssid.ssid_len = ssid->ssid_len;
203 bss->ssid.ssid_set = 1;
204
e62f4ed0
VN
205 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
206
0399f2e4
VT
207 if (ssid->auth_alg)
208 bss->auth_algs = ssid->auth_alg;
209
07f117ed
JM
210 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;
30c371e8 214 if (ssid->psk_set) {
07f117ed
JM
215 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;
30c371e8
MH
221 } else if (ssid->passphrase) {
222 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
6bcb1c2b
JM
223 } 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;
07f117ed
JM
239 }
240
07f53b8c
VT
241 if (ssid->ap_max_inactivity)
242 bss->ap_max_inactivity = ssid->ap_max_inactivity;
243
fdfb1c8b
EL
244 if (ssid->dtim_period)
245 bss->dtim_period = ssid->dtim_period;
18206e02
JM
246 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;
fdfb1c8b 253
cf830c1c
JM
254 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);
07d9a552
JM
258
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) {
697cd03f 264 int cipher = WPA_CIPHER_NONE;
07d9a552
JM
265 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
266 bss->ssid.wep.default_len = bss->default_wep_key_len;
697cd03f
JM
267 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;
07d9a552 277 bss->ssid.security_policy = SECURITY_STATIC_WEP;
697cd03f
JM
278 bss->wpa_group = cipher;
279 bss->wpa_pairwise = cipher;
280 bss->rsn_pairwise = cipher;
281 } else {
07d9a552 282 bss->ssid.security_policy = SECURITY_PLAINTEXT;
697cd03f
JM
283 bss->wpa_group = WPA_CIPHER_NONE;
284 bss->wpa_pairwise = WPA_CIPHER_NONE;
285 bss->rsn_pairwise = WPA_CIPHER_NONE;
286 }
07d9a552 287
2a07a276
JM
288 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
289 (bss->wpa_group == WPA_CIPHER_CCMP ||
30675c34
JM
290 bss->wpa_group == WPA_CIPHER_GCMP ||
291 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
292 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
2a07a276
JM
293 /*
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
3ec97afe
JM
300#ifdef CONFIG_WPS
301 /*
04ed4e98
JM
302 * 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.
3ec97afe 305 */
04ed4e98
JM
306 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
307 bss->ssid.security_policy != SECURITY_PLAINTEXT)
308 goto no_wps;
c0f83f31
JM
309#ifdef CONFIG_WPS2
310 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
cf830c1c 311 (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
c0f83f31
JM
312 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
313 * configuration */
314#endif /* CONFIG_WPS2 */
3ec97afe 315 bss->eap_server = 1;
e62f4ed0
VN
316
317 if (!ssid->ignore_broadcast_ssid)
318 bss->wps_state = 2;
319
9dd7d6b0 320 bss->ap_setup_locked = 2;
094393b1
JM
321 if (wpa_s->conf->config_methods)
322 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
2f646b6e
JB
323 os_memcpy(bss->device_type, wpa_s->conf->device_type,
324 WPS_DEV_TYPE_LEN);
e44f8bf2
JM
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 }
56815b2b
JM
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);
ab45223b
JM
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);
56815b2b 341 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
1298c145 342 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
04ed4e98 343no_wps:
56815b2b 344#endif /* CONFIG_WPS */
e44f8bf2 345
de979d8f
JM
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;
dae608d5 351
0d7e5a3a
JB
352 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
353
18a2eaab
JM
354 if (wpa_s->conf->ap_vendor_elements) {
355 bss->vendor_elements =
356 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
357 }
358
07f117ed
JM
359 return 0;
360}
361
362
c706d5aa
JM
363static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
364{
e44f8bf2
JM
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;
5ce00d09
JM
374 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
375 return;
e44f8bf2
JM
376 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
a0dee797
AGS
384static void ap_wps_event_cb(void *ctx, enum wps_event event,
385 union wps_event_data *data)
386{
ca806fb5 387#ifdef CONFIG_P2P
a0dee797 388 struct wpa_supplicant *wpa_s = ctx;
8be6450c
JMB
389
390 if (event == WPS_EV_FAIL) {
391 struct wps_event_fail *fail = &data->fail;
392
393 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);
a0dee797 405 }
ca806fb5 406#endif /* CONFIG_P2P */
a0dee797
AGS
407}
408
409
d8a43924 410static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
fbdcfd57 411 int authorized, const u8 *p2p_dev_addr)
d8a43924 412{
fbdcfd57 413 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
d8a43924
JB
414}
415
416
01a57fe4
JM
417#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
e44f8bf2
JM
430static 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;
c706d5aa
JM
447}
448
449
04a85e44 450static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
baf513d6
JB
451 const u8 *bssid, const u8 *ie, size_t ie_len,
452 int ssi_signal)
c706d5aa 453{
e44f8bf2
JM
454#ifdef CONFIG_P2P
455 struct wpa_supplicant *wpa_s = ctx;
baf513d6
JB
456 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
457 ssi_signal);
e44f8bf2 458#else /* CONFIG_P2P */
c706d5aa 459 return 0;
e44f8bf2 460#endif /* CONFIG_P2P */
c706d5aa
JM
461}
462
463
464static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
465 const u8 *uuid_e)
466{
e44f8bf2
JM
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 */
c706d5aa
JM
471}
472
473
c76e5d7f
JB
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
2d5b792d
JM
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;
f1a48710 493
2d5b792d
JM
494 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
495 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
496 return -1;
f1a48710
JM
497 }
498
2d5b792d 499 wpa_supplicant_ap_deinit(wpa_s);
d2440ba0
JM
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;
d7dcba70
JM
507 switch (ssid->mode) {
508 case WPAS_MODE_INFRA:
509 params.mode = IEEE80211_MODE_INFRA;
510 break;
511 case WPAS_MODE_IBSS:
512 params.mode = IEEE80211_MODE_IBSS;
513 break;
514 case WPAS_MODE_AP:
2c5d725c
JM
515 case WPAS_MODE_P2P_GO:
516 case WPAS_MODE_P2P_GROUP_FORMATION:
d7dcba70
JM
517 params.mode = IEEE80211_MODE_AP;
518 break;
519 }
973622cd
AS
520 if (ssid->frequency == 0)
521 ssid->frequency = 2462; /* default channel 11 */
d2440ba0
JM
522 params.freq = ssid->frequency;
523
64fa840a 524 params.wpa_proto = ssid->proto;
508545f3
JM
525 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
526 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
527 else
528 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
4848a38d 529 params.key_mgmt_suite = wpa_s->key_mgmt;
508545f3 530
edbd2a19
JM
531 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
532 1);
533 if (wpa_s->pairwise_cipher < 0) {
508545f3
JM
534 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
535 "cipher.");
536 return -1;
537 }
4848a38d 538 params.pairwise_suite = wpa_s->pairwise_cipher;
508545f3
JM
539 params.group_suite = params.pairwise_suite;
540
6e3f4b89
JM
541#ifdef CONFIG_P2P
542 if (ssid->mode == WPAS_MODE_P2P_GO ||
543 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
544 params.p2p = 1;
545#endif /* CONFIG_P2P */
546
eea2fd9e
JM
547 if (wpa_s->parent->set_ap_uapsd)
548 params.uapsd = wpa_s->parent->ap_uapsd;
549 else
550 params.uapsd = -1;
551
d2440ba0
JM
552 if (wpa_drv_associate(wpa_s, &params) < 0) {
553 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
554 return -1;
555 }
556
2d5b792d
JM
557 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
558 if (hapd_iface == NULL)
559 return -1;
0f2b2c19 560 hapd_iface->owner = wpa_s;
a57db49c 561 hapd_iface->drv_flags = wpa_s->drv_flags;
4f73d88a 562 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
8cd6b7bc
JB
563 hapd_iface->extended_capa = wpa_s->extended_capa;
564 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
565 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
1f1b62a0 566
2d5b792d
JM
567 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
568 if (conf == NULL) {
569 wpa_supplicant_ap_deinit(wpa_s);
570 return -1;
571 }
1f1b62a0 572
c26effe1
YD
573 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
574 wpa_s->conf->wmm_ac_params,
575 sizeof(wpa_s->conf->wmm_ac_params));
576
d26e45a4 577 if (params.uapsd > 0) {
ebd79f07
JM
578 conf->bss[0]->wmm_enabled = 1;
579 conf->bss[0]->wmm_uapsd = 1;
d26e45a4
EP
580 }
581
07f117ed
JM
582 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
583 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
584 wpa_supplicant_ap_deinit(wpa_s);
585 return -1;
586 }
587
e44f8bf2
JM
588#ifdef CONFIG_P2P
589 if (ssid->mode == WPAS_MODE_P2P_GO)
ebd79f07 590 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
e44f8bf2 591 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
ebd79f07 592 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
e44f8bf2
JM
593 P2P_GROUP_FORMATION;
594#endif /* CONFIG_P2P */
595
2d5b792d 596 hapd_iface->num_bss = conf->num_bss;
f9884c09 597 hapd_iface->bss = os_calloc(conf->num_bss,
2d5b792d
JM
598 sizeof(struct hostapd_data *));
599 if (hapd_iface->bss == NULL) {
600 wpa_supplicant_ap_deinit(wpa_s);
601 return -1;
602 }
1f1b62a0 603
2d5b792d
JM
604 for (i = 0; i < conf->num_bss; i++) {
605 hapd_iface->bss[i] =
606 hostapd_alloc_bss_data(hapd_iface, conf,
ebd79f07 607 conf->bss[i]);
2d5b792d
JM
608 if (hapd_iface->bss[i] == NULL) {
609 wpa_supplicant_ap_deinit(wpa_s);
610 return -1;
611 }
4f760fcc
JM
612
613 hapd_iface->bss[i]->msg_ctx = wpa_s;
8a5e75f6 614 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
c706d5aa
JM
615 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
616 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
e44f8bf2
JM
617 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
618 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
c706d5aa
JM
619 hostapd_register_probereq_cb(hapd_iface->bss[i],
620 ap_probe_req_rx, wpa_s);
621 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
622 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
a0dee797
AGS
623 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
624 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
d8a43924
JB
625 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
626 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
e44f8bf2 627#ifdef CONFIG_P2P
01a57fe4
JM
628 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
629 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
e44f8bf2 630 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
6f251b6b
JM
631 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
632 ssid);
e44f8bf2 633#endif /* CONFIG_P2P */
c76e5d7f
JB
634 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
635 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
2d5b792d
JM
636 }
637
a911a6e6
JM
638 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
639 hapd_iface->bss[0]->driver = wpa_s->driver;
640 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
641
e73edcaa 642 wpa_s->current_ssid = ssid;
25a8f9e3 643 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
e73edcaa
JM
644 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
645 wpa_s->assoc_freq = ssid->frequency;
646
a911a6e6 647 if (hostapd_setup_interface(wpa_s->ap_iface)) {
2d5b792d
JM
648 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
649 wpa_supplicant_ap_deinit(wpa_s);
650 return -1;
1f1b62a0
JM
651 }
652
2d5b792d
JM
653 return 0;
654}
655
656
657void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
658{
0fe620de 659#ifdef CONFIG_WPS
70d84f11 660 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
0fe620de 661#endif /* CONFIG_WPS */
70d84f11 662
2d5b792d
JM
663 if (wpa_s->ap_iface == NULL)
664 return;
665
7a649c7d 666 wpa_s->current_ssid = NULL;
25a8f9e3 667 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
3c85f144 668 wpa_s->assoc_freq = 0;
e44f8bf2 669#ifdef CONFIG_P2P
0e14267a
JM
670 if (wpa_s->ap_iface->bss)
671 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
e44f8bf2
JM
672 wpas_p2p_group_deinit(wpa_s);
673#endif /* CONFIG_P2P */
2d5b792d 674 hostapd_interface_deinit(wpa_s->ap_iface);
f7c47833 675 hostapd_interface_free(wpa_s->ap_iface);
2d5b792d 676 wpa_s->ap_iface = NULL;
7a649c7d 677 wpa_drv_deinit_ap(wpa_s);
1f1b62a0 678}
0915d02c
JM
679
680
681void ap_tx_status(void *ctx, const u8 *addr,
682 const u8 *buf, size_t len, int ack)
683{
f8b1f695 684#ifdef NEED_AP_MLME
0915d02c
JM
685 struct wpa_supplicant *wpa_s = ctx;
686 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
f8b1f695 687#endif /* NEED_AP_MLME */
0915d02c
JM
688}
689
690
dd840f79
JB
691void ap_eapol_tx_status(void *ctx, const u8 *dst,
692 const u8 *data, size_t len, int ack)
693{
694#ifdef NEED_AP_MLME
695 struct wpa_supplicant *wpa_s = ctx;
6fc61e18
JM
696 if (!wpa_s->ap_iface)
697 return;
dd840f79
JB
698 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
699#endif /* NEED_AP_MLME */
700}
701
702
bcf24348
JB
703void ap_client_poll_ok(void *ctx, const u8 *addr)
704{
705#ifdef NEED_AP_MLME
706 struct wpa_supplicant *wpa_s = ctx;
707 if (wpa_s->ap_iface)
708 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
709#endif /* NEED_AP_MLME */
710}
711
712
9b90955e 713void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
0915d02c 714{
f8b1f695 715#ifdef NEED_AP_MLME
0915d02c 716 struct wpa_supplicant *wpa_s = ctx;
9b90955e 717 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
f8b1f695 718#endif /* NEED_AP_MLME */
0915d02c
JM
719}
720
721
2a8b7416 722void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
0915d02c 723{
f8b1f695 724#ifdef NEED_AP_MLME
0915d02c 725 struct wpa_supplicant *wpa_s = ctx;
2a8b7416
JM
726 struct hostapd_frame_info fi;
727 os_memset(&fi, 0, sizeof(fi));
728 fi.datarate = rx_mgmt->datarate;
729 fi.ssi_signal = rx_mgmt->ssi_signal;
730 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
731 rx_mgmt->frame_len, &fi);
f8b1f695 732#endif /* NEED_AP_MLME */
0915d02c
JM
733}
734
735
f8b1f695 736void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
0915d02c 737{
f8b1f695 738#ifdef NEED_AP_MLME
0915d02c
JM
739 struct wpa_supplicant *wpa_s = ctx;
740 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
fe6bdb77 741#endif /* NEED_AP_MLME */
f8b1f695 742}
db149ac9
JM
743
744
745void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
746 const u8 *src_addr, const u8 *buf, size_t len)
747{
a8e0505b 748 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
db149ac9 749}
3ec97afe
JM
750
751
752#ifdef CONFIG_WPS
753
d601247c
JM
754int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
755 const u8 *p2p_dev_addr)
3ec97afe 756{
48b357a9
JM
757 if (!wpa_s->ap_iface)
758 return -1;
d601247c
JM
759 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
760 p2p_dev_addr);
3ec97afe
JM
761}
762
763
2f9929ff
AC
764int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
765{
766 struct wps_registrar *reg;
767 int reg_sel = 0, wps_sta = 0;
768
769 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
770 return -1;
771
772 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
773 reg_sel = wps_registrar_wps_cancel(reg);
774 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
4c374cde 775 ap_sta_wps_cancel, NULL);
2f9929ff
AC
776
777 if (!reg_sel && !wps_sta) {
778 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
779 "time");
780 return -1;
781 }
782
783 /*
784 * There are 2 cases to return wps cancel as success:
785 * 1. When wps cancel was initiated but no connection has been
786 * established with client yet.
787 * 2. Client is in the middle of exchanging WPS messages.
788 */
789
790 return 0;
791}
792
793
3ec97afe 794int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
c423708f
JM
795 const char *pin, char *buf, size_t buflen,
796 int timeout)
3ec97afe
JM
797{
798 int ret, ret_len = 0;
799
48b357a9
JM
800 if (!wpa_s->ap_iface)
801 return -1;
802
3ec97afe
JM
803 if (pin == NULL) {
804 unsigned int rpin = wps_generate_pin();
9337e876 805 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
3ec97afe 806 pin = buf;
f80a2237
JM
807 } else
808 ret_len = os_snprintf(buf, buflen, "%s", pin);
3ec97afe 809
31fcea93 810 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
c423708f 811 timeout);
3ec97afe
JM
812 if (ret)
813 return -1;
814 return ret_len;
815}
816
70d84f11
JM
817
818static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
819{
820 struct wpa_supplicant *wpa_s = eloop_data;
821 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
822 wpas_wps_ap_pin_disable(wpa_s);
823}
824
825
826static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
827{
828 struct hostapd_data *hapd;
829
830 if (wpa_s->ap_iface == NULL)
831 return;
832 hapd = wpa_s->ap_iface->bss[0];
833 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
834 hapd->ap_pin_failures = 0;
835 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
836 if (timeout > 0)
837 eloop_register_timeout(timeout, 0,
838 wpas_wps_ap_pin_timeout, wpa_s, NULL);
839}
840
841
842void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
843{
844 struct hostapd_data *hapd;
845
846 if (wpa_s->ap_iface == NULL)
847 return;
848 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
849 hapd = wpa_s->ap_iface->bss[0];
850 os_free(hapd->conf->ap_pin);
851 hapd->conf->ap_pin = NULL;
852 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
853}
854
855
856const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
857{
858 struct hostapd_data *hapd;
859 unsigned int pin;
860 char pin_txt[9];
861
862 if (wpa_s->ap_iface == NULL)
863 return NULL;
864 hapd = wpa_s->ap_iface->bss[0];
865 pin = wps_generate_pin();
9337e876 866 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
70d84f11
JM
867 os_free(hapd->conf->ap_pin);
868 hapd->conf->ap_pin = os_strdup(pin_txt);
869 if (hapd->conf->ap_pin == NULL)
870 return NULL;
871 wpas_wps_ap_pin_enable(wpa_s, timeout);
872
873 return hapd->conf->ap_pin;
874}
875
876
877const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
878{
879 struct hostapd_data *hapd;
880 if (wpa_s->ap_iface == NULL)
881 return NULL;
882 hapd = wpa_s->ap_iface->bss[0];
883 return hapd->conf->ap_pin;
884}
885
886
887int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
888 int timeout)
889{
890 struct hostapd_data *hapd;
891 char pin_txt[9];
892 int ret;
893
894 if (wpa_s->ap_iface == NULL)
895 return -1;
896 hapd = wpa_s->ap_iface->bss[0];
897 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
898 if (ret < 0 || ret >= (int) sizeof(pin_txt))
899 return -1;
900 os_free(hapd->conf->ap_pin);
901 hapd->conf->ap_pin = os_strdup(pin_txt);
902 if (hapd->conf->ap_pin == NULL)
903 return -1;
904 wpas_wps_ap_pin_enable(wpa_s, timeout);
905
906 return 0;
907}
908
909
910void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
911{
912 struct hostapd_data *hapd;
913
914 if (wpa_s->ap_iface == NULL)
915 return;
916 hapd = wpa_s->ap_iface->bss[0];
917
918 /*
919 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
920 * PIN if this happens multiple times to slow down brute force attacks.
921 */
922 hapd->ap_pin_failures++;
923 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
924 hapd->ap_pin_failures);
925 if (hapd->ap_pin_failures < 3)
926 return;
927
928 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
929 hapd->ap_pin_failures = 0;
930 os_free(hapd->conf->ap_pin);
931 hapd->conf->ap_pin = NULL;
932}
933
bbf41865 934
87470ea2
JM
935#ifdef CONFIG_WPS_NFC
936
bbf41865
JM
937struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
938 int ndef)
939{
940 struct hostapd_data *hapd;
941
942 if (wpa_s->ap_iface == NULL)
943 return NULL;
944 hapd = wpa_s->ap_iface->bss[0];
945 return hostapd_wps_nfc_config_token(hapd, ndef);
946}
947
5ab9a6a5
JM
948
949struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
950 int ndef)
951{
952 struct hostapd_data *hapd;
953
954 if (wpa_s->ap_iface == NULL)
955 return NULL;
956 hapd = wpa_s->ap_iface->bss[0];
957 return hostapd_wps_nfc_hs_cr(hapd, ndef);
958}
959
d9507936
JM
960
961int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
962 const struct wpabuf *req,
963 const struct wpabuf *sel)
964{
965 struct hostapd_data *hapd;
966
967 if (wpa_s->ap_iface == NULL)
968 return -1;
969 hapd = wpa_s->ap_iface->bss[0];
970 return hostapd_wps_nfc_report_handover(hapd, req, sel);
971}
972
87470ea2
JM
973#endif /* CONFIG_WPS_NFC */
974
3ec97afe 975#endif /* CONFIG_WPS */
e653b622
JM
976
977
35deb646
JM
978#ifdef CONFIG_CTRL_IFACE
979
e653b622
JM
980int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
981 char *buf, size_t buflen)
982{
983 if (wpa_s->ap_iface == NULL)
984 return -1;
985 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
986 buf, buflen);
987}
988
989
990int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
991 char *buf, size_t buflen)
992{
993 if (wpa_s->ap_iface == NULL)
994 return -1;
995 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
996 buf, buflen);
997}
998
999
1000int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1001 char *buf, size_t buflen)
1002{
1003 if (wpa_s->ap_iface == NULL)
1004 return -1;
1005 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
1006 buf, buflen);
1007}
35deb646 1008
43fb5297 1009
e60b2951
JJ
1010int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1011 const char *txtaddr)
1012{
1013 if (wpa_s->ap_iface == NULL)
1014 return -1;
1015 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1016 txtaddr);
1017}
1018
1019
1020int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1021 const char *txtaddr)
1022{
1023 if (wpa_s->ap_iface == NULL)
1024 return -1;
1025 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1026 txtaddr);
1027}
1028
1029
43fb5297
JM
1030int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1031 size_t buflen, int verbose)
1032{
1033 char *pos = buf, *end = buf + buflen;
1034 int ret;
1035 struct hostapd_bss_config *conf;
1036
1037 if (wpa_s->ap_iface == NULL)
1038 return -1;
1039
1040 conf = wpa_s->ap_iface->bss[0]->conf;
1041 if (conf->wpa == 0)
1042 return 0;
1043
1044 ret = os_snprintf(pos, end - pos,
1045 "pairwise_cipher=%s\n"
1046 "group_cipher=%s\n"
1047 "key_mgmt=%s\n",
1048 wpa_cipher_txt(conf->rsn_pairwise),
1049 wpa_cipher_txt(conf->wpa_group),
1050 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1051 conf->wpa));
1052 if (ret < 0 || ret >= end - pos)
1053 return pos - buf;
1054 pos += ret;
1055 return pos - buf;
1056}
1057
35deb646 1058#endif /* CONFIG_CTRL_IFACE */
f90ceeaa
JM
1059
1060
b22128ef
JM
1061int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1062{
1063 struct hostapd_iface *iface = wpa_s->ap_iface;
1064 struct wpa_ssid *ssid = wpa_s->current_ssid;
1065 struct hostapd_data *hapd;
1066
72d48a80
JM
1067 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1068 ssid->mode == WPAS_MODE_INFRA ||
1069 ssid->mode == WPAS_MODE_IBSS)
b22128ef
JM
1070 return -1;
1071
e44f8bf2
JM
1072#ifdef CONFIG_P2P
1073 if (ssid->mode == WPAS_MODE_P2P_GO)
ebd79f07 1074 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
e44f8bf2 1075 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
ebd79f07 1076 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
e44f8bf2
JM
1077 P2P_GROUP_FORMATION;
1078#endif /* CONFIG_P2P */
1079
b22128ef 1080 hapd = iface->bss[0];
72d48a80
JM
1081 if (hapd->drv_priv == NULL)
1082 return -1;
1083 ieee802_11_set_beacons(iface);
fe99fb74 1084 hostapd_set_ap_wps_ie(hapd);
b22128ef
JM
1085
1086 return 0;
1087}
1088
1089
bf281c12
AO
1090int ap_switch_channel(struct wpa_supplicant *wpa_s,
1091 struct csa_settings *settings)
1092{
1093#ifdef NEED_AP_MLME
1094 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1095 return -1;
1096
1097 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1098#else /* NEED_AP_MLME */
1099 return -1;
1100#endif /* NEED_AP_MLME */
1101}
1102
1103
334bf36a
AO
1104int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1105{
1106 struct csa_settings settings;
1107 int ret = hostapd_parse_csa_settings(pos, &settings);
1108
1109 if (ret)
1110 return ret;
1111
1112 return ap_switch_channel(wpa_s, &settings);
1113}
1114
1115
1b487b8b 1116void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
8d1fdde7 1117 int offset, int width, int cf1, int cf2)
1b487b8b
TP
1118{
1119 if (!wpa_s->ap_iface)
1120 return;
1121
1122 wpa_s->assoc_freq = freq;
8d1fdde7 1123 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
1b487b8b
TP
1124}
1125
1126
f90ceeaa
JM
1127int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1128 const u8 *addr)
1129{
1130 struct hostapd_data *hapd;
1131 struct hostapd_bss_config *conf;
1132
1133 if (!wpa_s->ap_iface)
1134 return -1;
1135
1136 if (addr)
1137 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1138 MAC2STR(addr));
1139 else
1140 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1141
1142 hapd = wpa_s->ap_iface->bss[0];
1143 conf = hapd->conf;
1144
1145 os_free(conf->accept_mac);
1146 conf->accept_mac = NULL;
1147 conf->num_accept_mac = 0;
1148 os_free(conf->deny_mac);
1149 conf->deny_mac = NULL;
1150 conf->num_deny_mac = 0;
1151
1152 if (addr == NULL) {
1153 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1154 return 0;
1155 }
1156
1157 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1158 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1159 if (conf->accept_mac == NULL)
1160 return -1;
1161 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1162 conf->num_accept_mac = 1;
1163
1164 return 0;
1165}
db6ae69e
JM
1166
1167
1168#ifdef CONFIG_WPS_NFC
1169int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1170 const struct wpabuf *pw, const u8 *pubkey_hash)
1171{
1172 struct hostapd_data *hapd;
1173 struct wps_context *wps;
1174
1175 if (!wpa_s->ap_iface)
1176 return -1;
1177 hapd = wpa_s->ap_iface->bss[0];
1178 wps = hapd->wps;
1179
1180 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1181 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1182 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1183 return -1;
1184 }
1185
1186 dh5_free(wps->dh_ctx);
1187 wpabuf_free(wps->dh_pubkey);
1188 wpabuf_free(wps->dh_privkey);
1189 wps->dh_privkey = wpabuf_dup(
1190 wpa_s->parent->conf->wps_nfc_dh_privkey);
1191 wps->dh_pubkey = wpabuf_dup(
1192 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1193 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1194 wps->dh_ctx = NULL;
1195 wpabuf_free(wps->dh_pubkey);
1196 wps->dh_pubkey = NULL;
1197 wpabuf_free(wps->dh_privkey);
1198 wps->dh_privkey = NULL;
1199 return -1;
1200 }
1201 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1202 if (wps->dh_ctx == NULL)
1203 return -1;
1204
1205 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1206 pw_id,
1207 pw ? wpabuf_head(pw) : NULL,
1208 pw ? wpabuf_len(pw) : 0, 1);
1209}
1210#endif /* CONFIG_WPS_NFC */