blob: 69bb0778a7681f00d7b689eeaf559c695b880b56 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
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"
17#include "eapol_supp/eapol_supp_sm.h"
18#include "crypto/dh_group5.h"
19#include "ap/hostapd.h"
20#include "ap/ap_config.h"
21#include "ap/ap_drv_ops.h"
22#ifdef NEED_AP_MLME
23#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"
29#include "ap/dfs.h"
30#include "wps/wps.h"
31#include "common/ieee802_11_defs.h"
32#include "config_ssid.h"
33#include "config.h"
34#include "wpa_supplicant_i.h"
35#include "driver_i.h"
36#include "p2p_supplicant.h"
37#include "ap.h"
38#include "ap/sta_info.h"
39#include "notify.h"
40
41
42#ifdef CONFIG_WPS
43static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
44#endif /* CONFIG_WPS */
45
46
47#ifdef CONFIG_P2P
48static bool is_chanwidth160_supported(struct hostapd_hw_modes *mode,
49 struct hostapd_config *conf)
50{
51#ifdef CONFIG_IEEE80211AX
52 if (conf->ieee80211ax) {
53 struct he_capabilities *he_cap;
54
55 he_cap = &mode->he_capab[IEEE80211_MODE_AP];
56 if (he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
57 (HE_PHYCAP_CHANNEL_WIDTH_SET_80PLUS80MHZ_IN_5G |
58 HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))
59 return true;
60 }
61#endif /* CONFIG_IEEE80211AX */
62 if (mode->vht_capab & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
63 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))
64 return true;
65 return false;
66}
67#endif /* CONFIG_P2P */
68
69
70static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
71 struct wpa_ssid *ssid,
72 struct hostapd_config *conf,
73 struct hostapd_hw_modes *mode)
74{
75#ifdef CONFIG_P2P
76 u8 center_chan = 0;
77 u8 channel = conf->channel;
78#endif /* CONFIG_P2P */
79 u8 freq_seg_idx;
80
81 if (!conf->secondary_channel)
82 goto no_vht;
83
84 /* Use the maximum oper channel width if it's given. */
85 if (ssid->max_oper_chwidth)
86 hostapd_set_oper_chwidth(conf, ssid->max_oper_chwidth);
87 if (hostapd_get_oper_chwidth(conf))
88 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
89 hostapd_get_oper_chwidth(conf),
90 &conf->op_class,
91 &conf->channel);
92
93 if (hostapd_get_oper_chwidth(conf) == CONF_OPER_CHWIDTH_80P80MHZ) {
94 ieee80211_freq_to_chan(ssid->vht_center_freq2,
95 &freq_seg_idx);
96 hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx);
97 }
98
99 if (!ssid->p2p_group) {
100 if (!ssid->vht_center_freq1)
101 goto no_vht;
102 ieee80211_freq_to_chan(ssid->vht_center_freq1,
103 &freq_seg_idx);
104 hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx);
105
106 wpa_printf(MSG_DEBUG,
107 "VHT seg0 index %d and seg1 index %d for AP",
108 hostapd_get_oper_centr_freq_seg0_idx(conf),
109 hostapd_get_oper_centr_freq_seg1_idx(conf));
110 return;
111 }
112
113#ifdef CONFIG_P2P
114 switch (hostapd_get_oper_chwidth(conf)) {
115 case CONF_OPER_CHWIDTH_80MHZ:
116 case CONF_OPER_CHWIDTH_80P80MHZ:
117 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel,
118 conf->op_class);
119 wpa_printf(MSG_DEBUG,
120 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
121 center_chan);
122 break;
123 case CONF_OPER_CHWIDTH_160MHZ:
124 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel,
125 conf->op_class);
126 wpa_printf(MSG_DEBUG,
127 "VHT center channel %u for 160 MHz bandwidth",
128 center_chan);
129 break;
130 default:
131 /*
132 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
133 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
134 * not supported.
135 */
136 hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_160MHZ);
137 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
138 conf->vht_oper_chwidth,
139 &conf->op_class,
140 &conf->channel);
141 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel,
142 conf->op_class);
143 if (center_chan && is_chanwidth160_supported(mode, conf)) {
144 wpa_printf(MSG_DEBUG,
145 "VHT center channel %u for auto-selected 160 MHz bandwidth",
146 center_chan);
147 } else {
148 hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_80MHZ);
149 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
150 conf->vht_oper_chwidth,
151 &conf->op_class,
152 &conf->channel);
153 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
154 channel,
155 conf->op_class);
156 wpa_printf(MSG_DEBUG,
157 "VHT center channel %u for auto-selected 80 MHz bandwidth",
158 center_chan);
159 }
160 break;
161 }
162 if (!center_chan)
163 goto no_vht;
164
165 hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan);
166 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
167 hostapd_get_oper_centr_freq_seg0_idx(conf));
168 return;
169#endif /* CONFIG_P2P */
170
171no_vht:
172 wpa_printf(MSG_DEBUG,
173 "No VHT higher bandwidth support for the selected channel %d",
174 conf->channel);
175 hostapd_set_oper_centr_freq_seg0_idx(
176 conf, conf->channel + conf->secondary_channel * 2);
177 hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_USE_HT);
178 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
179 conf->vht_oper_chwidth,
180 &conf->op_class, &conf->channel);
181}
182
183
184static struct hostapd_hw_modes *
185wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
186 enum hostapd_hw_mode hw_mode)
187{
188 struct hostapd_hw_modes *mode = NULL;
189 int i;
190
191 for (i = 0; i < wpa_s->hw.num_modes; i++) {
192 if (wpa_s->hw.modes[i].mode == hw_mode) {
193 mode = &wpa_s->hw.modes[i];
194 break;
195 }
196 }
197
198 return mode;
199}
200
201
202#ifdef CONFIG_P2P
203
204static int get_max_oper_chwidth_6ghz(int chwidth)
205{
206 switch (chwidth) {
207 case CONF_OPER_CHWIDTH_USE_HT:
208 return 20;
209 case CONF_OPER_CHWIDTH_40MHZ_6GHZ:
210 return 40;
211 case CONF_OPER_CHWIDTH_80MHZ:
212 return 80;
213 case CONF_OPER_CHWIDTH_80P80MHZ:
214 case CONF_OPER_CHWIDTH_160MHZ:
215 return 160;
216 default:
217 return 0;
218 }
219}
220
221
222static void wpas_conf_ap_he_6ghz(struct wpa_supplicant *wpa_s,
223 struct hostapd_hw_modes *mode,
224 struct wpa_ssid *ssid,
225 struct hostapd_config *conf)
226{
227 bool is_chanwidth_40_80, is_chanwidth_160;
228 int he_chanwidth;
229
230 he_chanwidth =
231 mode->he_capab[wpas_mode_to_ieee80211_mode(
232 ssid->mode)].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX];
233 is_chanwidth_40_80 = he_chanwidth &
234 HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
235 is_chanwidth_160 = he_chanwidth &
236 HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
237
238 wpa_printf(MSG_DEBUG,
239 "Enable HE support (p2p_group=%d he_chwidth_cap=%d)",
240 ssid->p2p_group, he_chanwidth);
241
242 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
243 ssid->mode)].he_supported &&
244 ssid->he)
245 conf->ieee80211ax = 1;
246
247 if (is_chanwidth_40_80 && ssid->p2p_group &&
248 get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 40) {
249 conf->secondary_channel =
250 wpas_p2p_get_sec_channel_offset_40mhz(
251 wpa_s, mode, conf->channel);
252 wpa_printf(MSG_DEBUG,
253 "Secondary channel offset %d for P2P group",
254 conf->secondary_channel);
255 if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_40MHZ_6GHZ)
256 ssid->max_oper_chwidth = CONF_OPER_CHWIDTH_USE_HT;
257 }
258
259 if ((is_chanwidth_40_80 || is_chanwidth_160) && ssid->p2p_group &&
260 get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 80)
261 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
262}
263
264#endif /* CONFIG_P2P */
265
266
267int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
268 struct wpa_ssid *ssid,
269 struct hostapd_config *conf)
270{
271 conf->hw_mode = ieee80211_freq_to_channel_ext(ssid->frequency, 0,
272 CONF_OPER_CHWIDTH_USE_HT,
273 &conf->op_class,
274 &conf->channel);
275 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
276 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
277 ssid->frequency);
278 return -1;
279 }
280
281 /*
282 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
283 * and a mask of allowed capabilities within conf->ht_capab.
284 * Using default config settings for: conf->ht_op_mode_fixed,
285 * conf->secondary_channel, conf->require_ht
286 */
287 if (wpa_s->hw.modes) {
288 struct hostapd_hw_modes *mode = NULL;
289 int no_ht = 0;
290
291 wpa_printf(MSG_DEBUG,
292 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
293 ssid->frequency, conf->channel);
294
295 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
296 conf->hw_mode, is_6ghz_freq(ssid->frequency));
297
298 /* May drop to IEEE 802.11b if the driver does not support IEEE
299 * 802.11g */
300 if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
301 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
302 wpa_printf(MSG_INFO,
303 "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
304 mode = wpa_supplicant_find_hw_mode(wpa_s,
305 conf->hw_mode);
306 }
307
308 if (!mode) {
309 wpa_printf(MSG_ERROR,
310 "No match between requested and supported hw modes found");
311 return -1;
312 }
313
314#ifdef CONFIG_HT_OVERRIDES
315 if (ssid->disable_ht)
316 ssid->ht = 0;
317#endif /* CONFIG_HT_OVERRIDES */
318
319 if (!ssid->ht) {
320 wpa_printf(MSG_DEBUG,
321 "HT not enabled in network profile");
322 conf->ieee80211n = 0;
323 conf->ht_capab = 0;
324 no_ht = 1;
325 }
326
327 if (mode && is_6ghz_freq(ssid->frequency) &&
328 conf->hw_mode == HOSTAPD_MODE_IEEE80211A) {
329 if (mode->eht_capab[wpas_mode_to_ieee80211_mode(
330 ssid->mode)].eht_supported &&
331 ssid->eht)
332 conf->ieee80211be = 1;
333
334 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
335 ssid->mode)].he_supported &&
336 ssid->he)
337 conf->ieee80211ax = 1;
338
339#ifdef CONFIG_P2P
340 wpas_conf_ap_he_6ghz(wpa_s, mode, ssid, conf);
341#endif /* CONFIG_P2P */
342 } else if (!no_ht && mode && mode->ht_capab) {
343 wpa_printf(MSG_DEBUG,
344 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
345 ssid->p2p_group,
346 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
347 !!(mode->ht_capab &
348 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
349 ssid->ht40);
350 conf->ieee80211n = 1;
351
352 if (ssid->ht40 &&
353 (mode->ht_capab &
354 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
355 conf->secondary_channel = ssid->ht40;
356 else
357 conf->secondary_channel = 0;
358
359#ifdef CONFIG_P2P
360 if (ssid->p2p_group &&
361 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
362 (mode->ht_capab &
363 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
364 ssid->ht40) {
365 conf->secondary_channel =
366 wpas_p2p_get_sec_channel_offset_40mhz(
367 wpa_s, mode, conf->channel);
368 wpa_printf(MSG_DEBUG,
369 "HT secondary channel offset %d for P2P group",
370 conf->secondary_channel);
371 } else if (ssid->p2p_group && conf->secondary_channel &&
372 conf->hw_mode != HOSTAPD_MODE_IEEE80211A) {
373 /* This ended up trying to configure invalid
374 * 2.4 GHz channels (e.g., HT40+ on channel 11)
375 * in some cases, so clear the secondary channel
376 * configuration now to avoid such cases that
377 * would lead to group formation failures. */
378 wpa_printf(MSG_DEBUG,
379 "Disable HT secondary channel for P2P group on 2.4 GHz");
380 conf->secondary_channel = 0;
381 }
382#endif /* CONFIG_P2P */
383
384 if (!ssid->p2p_group &&
385 (mode->ht_capab &
386 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
387 conf->secondary_channel = ssid->ht40;
388 wpa_printf(MSG_DEBUG,
389 "HT secondary channel offset %d for AP",
390 conf->secondary_channel);
391 }
392
393 if (conf->secondary_channel)
394 conf->ht_capab |=
395 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
396
397 /*
398 * include capabilities that won't cause issues
399 * to connecting stations, while leaving the current
400 * capabilities intact (currently disabled SMPS).
401 */
402 conf->ht_capab |= mode->ht_capab &
403 (HT_CAP_INFO_GREEN_FIELD |
404 HT_CAP_INFO_SHORT_GI20MHZ |
405 HT_CAP_INFO_SHORT_GI40MHZ |
406 HT_CAP_INFO_RX_STBC_MASK |
407 HT_CAP_INFO_TX_STBC |
408 HT_CAP_INFO_MAX_AMSDU_SIZE);
409
410 /* check this before VHT, because setting oper chan
411 * width and friends is the same call for HE and VHT
412 * and checks if conf->ieee8021ax == 1 */
413 if (mode->eht_capab[wpas_mode_to_ieee80211_mode(
414 ssid->mode)].eht_supported &&
415 ssid->eht)
416 conf->ieee80211be = 1;
417
418 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
419 ssid->mode)].he_supported &&
420 ssid->he)
421 conf->ieee80211ax = 1;
422
423 if (mode->vht_capab && ssid->vht) {
424 conf->ieee80211ac = 1;
425 conf->vht_capab |= mode->vht_capab;
426 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
427 }
428 }
429 }
430
431 if (conf->secondary_channel) {
432 struct wpa_supplicant *iface;
433
434 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
435 {
436 if (iface == wpa_s ||
437 iface->wpa_state < WPA_AUTHENTICATING ||
438 (int) iface->assoc_freq != ssid->frequency)
439 continue;
440
441 /*
442 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
443 * to change our PRI channel since we have an existing,
444 * concurrent connection on that channel and doing
445 * multi-channel concurrency is likely to cause more
446 * harm than using different PRI/SEC selection in
447 * environment with multiple BSSes on these two channels
448 * with mixed 20 MHz or PRI channel selection.
449 */
450 conf->no_pri_sec_switch = 1;
451 }
452 }
453
454 return 0;
455}
456
457
458static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
459 struct wpa_ssid *ssid,
460 struct hostapd_config *conf)
461{
462 struct hostapd_bss_config *bss = conf->bss[0];
463
464 conf->driver = wpa_s->driver;
465
466 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
467
468 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
469 return -1;
470
471 if (ssid->pbss > 1) {
472 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
473 ssid->pbss);
474 return -1;
475 }
476 bss->pbss = ssid->pbss;
477
478#ifdef CONFIG_ACS
479 if (ssid->acs) {
480 /* Setting channel to 0 in order to enable ACS */
481 conf->channel = 0;
482 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
483 }
484#endif /* CONFIG_ACS */
485
486 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
487 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
488 conf->ieee80211h = 1;
489 conf->ieee80211d = 1;
490 conf->country[0] = wpa_s->conf->country[0];
491 conf->country[1] = wpa_s->conf->country[1];
492 conf->country[2] = ' ';
493 }
494
495#ifdef CONFIG_P2P
496 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
497 (ssid->mode == WPAS_MODE_P2P_GO ||
498 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
499 /* Remove 802.11b rates from supported and basic rate sets */
500 int *list = os_malloc(4 * sizeof(int));
501 if (list) {
502 list[0] = 60;
503 list[1] = 120;
504 list[2] = 240;
505 list[3] = -1;
506 }
507 conf->basic_rates = list;
508
509 list = os_malloc(9 * sizeof(int));
510 if (list) {
511 list[0] = 60;
512 list[1] = 90;
513 list[2] = 120;
514 list[3] = 180;
515 list[4] = 240;
516 list[5] = 360;
517 list[6] = 480;
518 list[7] = 540;
519 list[8] = -1;
520 }
521 conf->supported_rates = list;
522 }
523
524#ifdef CONFIG_IEEE80211AX
525 if (ssid->mode == WPAS_MODE_P2P_GO ||
526 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
527 conf->ieee80211ax = ssid->he;
528#endif /* CONFIG_IEEE80211AX */
529
530 bss->isolate = !wpa_s->conf->p2p_intra_bss;
531 bss->extended_key_id = wpa_s->conf->extended_key_id;
532 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
533 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
534
535 if (ssid->p2p_group) {
536 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
537 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
538 4);
539 os_memcpy(bss->ip_addr_start,
540 wpa_s->p2pdev->conf->ip_addr_start, 4);
541 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
542 4);
543 }
544#endif /* CONFIG_P2P */
545
546 if (ssid->ssid_len == 0) {
547 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
548 return -1;
549 }
550 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
551 bss->ssid.ssid_len = ssid->ssid_len;
552 bss->ssid.ssid_set = 1;
553
554 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
555
556 if (ssid->auth_alg)
557 bss->auth_algs = ssid->auth_alg;
558
559 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
560 bss->wpa = ssid->proto;
561 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
562 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
563 else
564 bss->wpa_key_mgmt = ssid->key_mgmt;
565 bss->wpa_pairwise = ssid->pairwise_cipher;
566 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
567 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
568 } else if (ssid->psk_set) {
569 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
570 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
571 if (bss->ssid.wpa_psk == NULL)
572 return -1;
573 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
574 bss->ssid.wpa_psk->group = 1;
575 bss->ssid.wpa_psk_set = 1;
576 } else if (ssid->passphrase) {
577 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
578#ifdef CONFIG_WEP
579 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
580 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
581 struct hostapd_wep_keys *wep = &bss->ssid.wep;
582 int i;
583 for (i = 0; i < NUM_WEP_KEYS; i++) {
584 if (ssid->wep_key_len[i] == 0)
585 continue;
586 wep->key[i] = os_memdup(ssid->wep_key[i],
587 ssid->wep_key_len[i]);
588 if (wep->key[i] == NULL)
589 return -1;
590 wep->len[i] = ssid->wep_key_len[i];
591 }
592 wep->idx = ssid->wep_tx_keyidx;
593 wep->keys_set = 1;
594#endif /* CONFIG_WEP */
595 }
596#ifdef CONFIG_SAE
597 if (ssid->sae_password) {
598 struct sae_password_entry *pw;
599
600 pw = os_zalloc(sizeof(*pw));
601 if (!pw)
602 return -1;
603 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
604 pw->password = os_strdup(ssid->sae_password);
605 if (!pw->password) {
606 os_free(pw);
607 return -1;
608 }
609 if (ssid->sae_password_id) {
610 pw->identifier = os_strdup(ssid->sae_password_id);
611 if (!pw->identifier) {
612 str_clear_free(pw->password);
613 os_free(pw);
614 return -1;
615 }
616 }
617
618 pw->next = bss->sae_passwords;
619 bss->sae_passwords = pw;
620 }
621
622 if (ssid->sae_pwe != DEFAULT_SAE_PWE)
623 bss->sae_pwe = ssid->sae_pwe;
624 else
625 bss->sae_pwe = wpa_s->conf->sae_pwe;
626#endif /* CONFIG_SAE */
627
628 if (wpa_s->conf->go_interworking) {
629 wpa_printf(MSG_DEBUG,
630 "P2P: Enable Interworking with access_network_type: %d",
631 wpa_s->conf->go_access_network_type);
632 bss->interworking = wpa_s->conf->go_interworking;
633 bss->access_network_type = wpa_s->conf->go_access_network_type;
634 bss->internet = wpa_s->conf->go_internet;
635 if (wpa_s->conf->go_venue_group) {
636 wpa_printf(MSG_DEBUG,
637 "P2P: Venue group: %d Venue type: %d",
638 wpa_s->conf->go_venue_group,
639 wpa_s->conf->go_venue_type);
640 bss->venue_group = wpa_s->conf->go_venue_group;
641 bss->venue_type = wpa_s->conf->go_venue_type;
642 bss->venue_info_set = 1;
643 }
644 }
645
646 if (ssid->ap_max_inactivity)
647 bss->ap_max_inactivity = ssid->ap_max_inactivity;
648
649 if (ssid->dtim_period)
650 bss->dtim_period = ssid->dtim_period;
651 else if (wpa_s->conf->dtim_period)
652 bss->dtim_period = wpa_s->conf->dtim_period;
653
654 if (ssid->beacon_int)
655 conf->beacon_int = ssid->beacon_int;
656 else if (wpa_s->conf->beacon_int)
657 conf->beacon_int = wpa_s->conf->beacon_int;
658
659#ifdef CONFIG_P2P
660 if (ssid->mode == WPAS_MODE_P2P_GO ||
661 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
662 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
663 wpa_printf(MSG_INFO,
664 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
665 wpa_s->conf->p2p_go_ctwindow,
666 conf->beacon_int);
667 conf->p2p_go_ctwindow = 0;
668 } else {
669 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
670 }
671 }
672#endif /* CONFIG_P2P */
673
674 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
675 bss->rsn_pairwise = bss->wpa_pairwise;
676 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
677 bss->rsn_pairwise);
678
679 if (bss->wpa && bss->ieee802_1x) {
680 bss->ssid.security_policy = SECURITY_WPA;
681 } else if (bss->wpa) {
682 bss->ssid.security_policy = SECURITY_WPA_PSK;
683#ifdef CONFIG_WEP
684 } else if (bss->ieee802_1x) {
685 int cipher = WPA_CIPHER_NONE;
686 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
687 bss->ssid.wep.default_len = bss->default_wep_key_len;
688 if (bss->default_wep_key_len)
689 cipher = bss->default_wep_key_len >= 13 ?
690 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
691 bss->wpa_group = cipher;
692 bss->wpa_pairwise = cipher;
693 bss->rsn_pairwise = cipher;
694 } else if (bss->ssid.wep.keys_set) {
695 int cipher = WPA_CIPHER_WEP40;
696 if (bss->ssid.wep.len[0] >= 13)
697 cipher = WPA_CIPHER_WEP104;
698 bss->ssid.security_policy = SECURITY_STATIC_WEP;
699 bss->wpa_group = cipher;
700 bss->wpa_pairwise = cipher;
701 bss->rsn_pairwise = cipher;
702#endif /* CONFIG_WEP */
703 } else {
704 bss->ssid.security_policy = SECURITY_PLAINTEXT;
705 bss->wpa_group = WPA_CIPHER_NONE;
706 bss->wpa_pairwise = WPA_CIPHER_NONE;
707 bss->rsn_pairwise = WPA_CIPHER_NONE;
708 }
709
710 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
711 (bss->wpa_group == WPA_CIPHER_CCMP ||
712 bss->wpa_group == WPA_CIPHER_GCMP ||
713 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
714 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
715 /*
716 * Strong ciphers do not need frequent rekeying, so increase
717 * the default GTK rekeying period to 24 hours.
718 */
719 bss->wpa_group_rekey = 86400;
720 }
721
722 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT) {
723 bss->ieee80211w = ssid->ieee80211w;
724 } else if (wpa_s->conf->pmf != MGMT_FRAME_PROTECTION_DEFAULT) {
725 if (ssid->mode == WPAS_MODE_AP)
726 bss->ieee80211w = wpa_s->conf->pmf;
727 }
728
729#ifdef CONFIG_OCV
730 bss->ocv = ssid->ocv;
731#endif /* CONFIG_OCV */
732
733#ifdef CONFIG_WPS
734 /*
735 * Enable WPS by default for open and WPA/WPA2-Personal network, but
736 * require user interaction to actually use it. Only the internal
737 * Registrar is supported.
738 */
739 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
740 bss->ssid.security_policy != SECURITY_PLAINTEXT)
741 goto no_wps;
742 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
743 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
744 !(bss->wpa & 2)))
745 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
746 * configuration */
747 if (ssid->wps_disabled)
748 goto no_wps;
749 bss->eap_server = 1;
750
751 if (!ssid->ignore_broadcast_ssid)
752 bss->wps_state = 2;
753
754 bss->ap_setup_locked = 2;
755 if (wpa_s->conf->config_methods)
756 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
757 os_memcpy(bss->device_type, wpa_s->conf->device_type,
758 WPS_DEV_TYPE_LEN);
759 if (wpa_s->conf->device_name) {
760 bss->device_name = os_strdup(wpa_s->conf->device_name);
761 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
762 }
763 if (wpa_s->conf->manufacturer)
764 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
765 if (wpa_s->conf->model_name)
766 bss->model_name = os_strdup(wpa_s->conf->model_name);
767 if (wpa_s->conf->model_number)
768 bss->model_number = os_strdup(wpa_s->conf->model_number);
769 if (wpa_s->conf->serial_number)
770 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
771 if (is_nil_uuid(wpa_s->conf->uuid))
772 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
773 else
774 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
775 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
776 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
777 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
778 bss->fragment_size = ssid->eap.fragment_size;
779no_wps:
780#endif /* CONFIG_WPS */
781
782 if (wpa_s->max_stations &&
783 wpa_s->max_stations < wpa_s->conf->max_num_sta)
784 bss->max_num_sta = wpa_s->max_stations;
785 else
786 bss->max_num_sta = wpa_s->conf->max_num_sta;
787
788 if (!bss->isolate)
789 bss->isolate = wpa_s->conf->ap_isolate;
790
791 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
792
793 if (wpa_s->conf->ap_vendor_elements) {
794 bss->vendor_elements =
795 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
796 }
797 if (wpa_s->conf->ap_assocresp_elements) {
798 bss->assocresp_elements =
799 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
800 }
801
802 bss->ftm_responder = wpa_s->conf->ftm_responder;
803 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
804
805 bss->transition_disable = ssid->transition_disable;
806
807 return 0;
808}
809
810
811static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
812{
813#ifdef CONFIG_P2P
814 struct wpa_supplicant *wpa_s = ctx;
815 const struct ieee80211_mgmt *mgmt;
816
817 mgmt = (const struct ieee80211_mgmt *) buf;
818 if (len < IEEE80211_HDRLEN + 1)
819 return;
820 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
821 return;
822 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
823 mgmt->u.action.category,
824 buf + IEEE80211_HDRLEN + 1,
825 len - IEEE80211_HDRLEN - 1, freq);
826#endif /* CONFIG_P2P */
827}
828
829
830static void ap_wps_event_cb(void *ctx, enum wps_event event,
831 union wps_event_data *data)
832{
833#ifdef CONFIG_P2P
834 struct wpa_supplicant *wpa_s = ctx;
835
836 if (event == WPS_EV_FAIL) {
837 struct wps_event_fail *fail = &data->fail;
838
839 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
840 wpa_s == wpa_s->global->p2p_group_formation) {
841 /*
842 * src/ap/wps_hostapd.c has already sent this on the
843 * main interface, so only send on the parent interface
844 * here if needed.
845 */
846 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
847 "msg=%d config_error=%d",
848 fail->msg, fail->config_error);
849 }
850 wpas_p2p_wps_failed(wpa_s, fail);
851 }
852#endif /* CONFIG_P2P */
853}
854
855
856static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
857 int authorized, const u8 *p2p_dev_addr)
858{
859 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
860}
861
862
863#ifdef CONFIG_P2P
864static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
865 const u8 *psk, size_t psk_len)
866{
867
868 struct wpa_supplicant *wpa_s = ctx;
869 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
870 return;
871 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
872}
873#endif /* CONFIG_P2P */
874
875
876static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
877{
878#ifdef CONFIG_P2P
879 struct wpa_supplicant *wpa_s = ctx;
880 const struct ieee80211_mgmt *mgmt;
881
882 mgmt = (const struct ieee80211_mgmt *) buf;
883 if (len < IEEE80211_HDRLEN + 1)
884 return -1;
885 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
886 mgmt->u.action.category,
887 buf + IEEE80211_HDRLEN + 1,
888 len - IEEE80211_HDRLEN - 1, freq);
889#endif /* CONFIG_P2P */
890 return 0;
891}
892
893
894static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
895 const u8 *bssid, const u8 *ie, size_t ie_len,
896 int ssi_signal)
897{
898 struct wpa_supplicant *wpa_s = ctx;
899 unsigned int freq = 0;
900
901 if (wpa_s->ap_iface)
902 freq = wpa_s->ap_iface->freq;
903
904 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
905 freq, ssi_signal);
906}
907
908
909static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
910 const u8 *uuid_e)
911{
912 struct wpa_supplicant *wpa_s = ctx;
913 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
914}
915
916
917static void wpas_ap_configured_cb(void *ctx)
918{
919 struct wpa_supplicant *wpa_s = ctx;
920
921 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
922 hostapd_state_text(wpa_s->ap_iface->state));
923 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
924 wpa_supplicant_ap_deinit(wpa_s);
925 return;
926 }
927
928 if (wpa_s->current_ssid) {
929 int acs = 0;
930
931#ifdef CONFIG_ACS
932 acs = wpa_s->current_ssid->acs;
933#endif /* CONFIG_ACS */
934 if (acs || (wpa_s->assoc_freq && wpa_s->ap_iface->freq &&
935 (int) wpa_s->assoc_freq != wpa_s->ap_iface->freq)) {
936 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
937 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
938 }
939 }
940
941 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
942
943 if (wpa_s->ap_configured_cb)
944 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
945 wpa_s->ap_configured_cb_data);
946}
947
948
949int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
950 struct wpa_ssid *ssid)
951{
952 struct wpa_driver_associate_params params;
953 struct hostapd_iface *hapd_iface;
954 struct hostapd_config *conf;
955 size_t i;
956
957 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
958 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
959 return -1;
960 }
961
962 wpa_supplicant_ap_deinit(wpa_s);
963
964 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
965 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
966
967 os_memset(&params, 0, sizeof(params));
968 params.ssid = ssid->ssid;
969 params.ssid_len = ssid->ssid_len;
970 switch (ssid->mode) {
971 case WPAS_MODE_AP:
972 case WPAS_MODE_P2P_GO:
973 case WPAS_MODE_P2P_GROUP_FORMATION:
974 params.mode = IEEE80211_MODE_AP;
975 break;
976 default:
977 return -1;
978 }
979 if (ssid->frequency == 0)
980 ssid->frequency = 2462; /* default channel 11 */
981 params.freq.freq = ssid->frequency;
982
983 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
984 ssid->enable_edmg) {
985 u8 primary_channel;
986
987 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
988 NUM_HOSTAPD_MODES) {
989 wpa_printf(MSG_WARNING,
990 "EDMG: Failed to get the primary channel");
991 return -1;
992 }
993
994 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
995 primary_channel, &params.freq.edmg);
996 }
997
998 params.wpa_proto = ssid->proto;
999 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
1000 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
1001 else if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
1002 wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
1003 else
1004 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
1005 params.key_mgmt_suite = wpa_s->key_mgmt;
1006
1007 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
1008 1);
1009 if (wpa_s->pairwise_cipher < 0) {
1010 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
1011 "cipher.");
1012 return -1;
1013 }
1014 params.pairwise_suite = wpa_s->pairwise_cipher;
1015 params.group_suite = params.pairwise_suite;
1016
1017#ifdef CONFIG_P2P
1018 if (ssid->mode == WPAS_MODE_P2P_GO ||
1019 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1020 params.p2p = 1;
1021#endif /* CONFIG_P2P */
1022
1023 if (wpa_s->p2pdev->set_ap_uapsd)
1024 params.uapsd = wpa_s->p2pdev->ap_uapsd;
1025 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1026 params.uapsd = 1; /* mandatory for P2P GO */
1027 else
1028 params.uapsd = -1;
1029
1030 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
1031 wpa_s->hw.num_modes))
1032 params.freq.freq = 0; /* set channel after CAC */
1033
1034 if (params.p2p)
1035 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
1036 else
1037 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
1038
1039 if (wpa_drv_associate(wpa_s, &params) < 0) {
1040 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
1041 return -1;
1042 }
1043
1044 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
1045 if (hapd_iface == NULL)
1046 return -1;
1047 hapd_iface->owner = wpa_s;
1048 hapd_iface->drv_flags = wpa_s->drv_flags;
1049 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
1050 hapd_iface->extended_capa = wpa_s->extended_capa;
1051 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
1052 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
1053 hapd_iface->drv_max_acl_mac_addrs = wpa_s->drv_max_acl_mac_addrs;
1054
1055 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
1056 if (conf == NULL) {
1057 wpa_supplicant_ap_deinit(wpa_s);
1058 return -1;
1059 }
1060
1061 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
1062 wpa_s->conf->wmm_ac_params,
1063 sizeof(wpa_s->conf->wmm_ac_params));
1064
1065 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
1066 sizeof(wpa_s->conf->tx_queue));
1067
1068 if (params.uapsd > 0) {
1069 conf->bss[0]->wmm_enabled = 1;
1070 conf->bss[0]->wmm_uapsd = 1;
1071 }
1072
1073 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
1074 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
1075 wpa_supplicant_ap_deinit(wpa_s);
1076 return -1;
1077 }
1078
1079#ifdef CONFIG_P2P
1080 if (ssid->mode == WPAS_MODE_P2P_GO)
1081 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
1082 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1083 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
1084 P2P_GROUP_FORMATION;
1085#endif /* CONFIG_P2P */
1086
1087 hapd_iface->num_bss = conf->num_bss;
1088 hapd_iface->bss = os_calloc(conf->num_bss,
1089 sizeof(struct hostapd_data *));
1090 if (hapd_iface->bss == NULL) {
1091 wpa_supplicant_ap_deinit(wpa_s);
1092 return -1;
1093 }
1094
1095 for (i = 0; i < conf->num_bss; i++) {
1096 hapd_iface->bss[i] =
1097 hostapd_alloc_bss_data(hapd_iface, conf,
1098 conf->bss[i]);
1099 if (hapd_iface->bss[i] == NULL) {
1100 wpa_supplicant_ap_deinit(wpa_s);
1101 return -1;
1102 }
1103
1104 hapd_iface->bss[i]->msg_ctx = wpa_s;
1105 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
1106 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
1107 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
1108 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
1109 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
1110 hostapd_register_probereq_cb(hapd_iface->bss[i],
1111 ap_probe_req_rx, wpa_s);
1112 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
1113 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
1114 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
1115 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
1116 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
1117 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
1118#ifdef CONFIG_P2P
1119 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
1120 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
1121 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
1122 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
1123 ssid);
1124#endif /* CONFIG_P2P */
1125 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
1126 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
1127#ifdef CONFIG_TESTING_OPTIONS
1128 hapd_iface->bss[i]->ext_eapol_frame_io =
1129 wpa_s->ext_eapol_frame_io;
1130#endif /* CONFIG_TESTING_OPTIONS */
1131
1132#ifdef CONFIG_WNM_AP
1133 if (ssid->mode == WPAS_MODE_AP)
1134 hapd_iface->bss[i]->conf->bss_transition = 1;
1135#endif /* CONFIG_WNM_AP */
1136 }
1137
1138 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
1139 hapd_iface->bss[0]->driver = wpa_s->driver;
1140 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
1141
1142 wpa_s->current_ssid = ssid;
1143 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1144 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1145 wpa_s->assoc_freq = ssid->frequency;
1146 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1147 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
1148
1149#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1150 if (wpa_s->p2p_go_do_acs) {
1151 wpa_s->ap_iface->conf->channel = 0;
1152 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1153 ssid->acs = 1;
1154 }
1155#endif /* CONFIG_P2P && CONFIG_ACS */
1156
1157 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1158 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1159 wpa_supplicant_ap_deinit(wpa_s);
1160 return -1;
1161 }
1162
1163 return 0;
1164}
1165
1166
1167void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1168{
1169#ifdef CONFIG_WPS
1170 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1171#endif /* CONFIG_WPS */
1172
1173 if (wpa_s->ap_iface == NULL)
1174 return;
1175
1176 wpa_s->current_ssid = NULL;
1177 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1178 wpa_s->assoc_freq = 0;
1179 wpas_p2p_ap_deinit(wpa_s);
1180 wpa_s->ap_iface->driver_ap_teardown =
1181 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1182
1183 hostapd_interface_deinit(wpa_s->ap_iface);
1184 hostapd_interface_free(wpa_s->ap_iface);
1185 wpa_s->ap_iface = NULL;
1186 wpa_drv_deinit_ap(wpa_s);
1187 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1188 " reason=%d locally_generated=1",
1189 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
1190}
1191
1192
1193void ap_tx_status(void *ctx, const u8 *addr,
1194 const u8 *buf, size_t len, int ack)
1195{
1196#ifdef NEED_AP_MLME
1197 struct wpa_supplicant *wpa_s = ctx;
1198 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1199#endif /* NEED_AP_MLME */
1200}
1201
1202
1203void ap_eapol_tx_status(void *ctx, const u8 *dst,
1204 const u8 *data, size_t len, int ack)
1205{
1206#ifdef NEED_AP_MLME
1207 struct wpa_supplicant *wpa_s = ctx;
1208 if (!wpa_s->ap_iface)
1209 return;
1210 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1211#endif /* NEED_AP_MLME */
1212}
1213
1214
1215void ap_client_poll_ok(void *ctx, const u8 *addr)
1216{
1217#ifdef NEED_AP_MLME
1218 struct wpa_supplicant *wpa_s = ctx;
1219 if (wpa_s->ap_iface)
1220 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1221#endif /* NEED_AP_MLME */
1222}
1223
1224
1225void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1226{
1227#ifdef NEED_AP_MLME
1228 struct wpa_supplicant *wpa_s = ctx;
1229 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
1230#endif /* NEED_AP_MLME */
1231}
1232
1233
1234void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1235{
1236#ifdef NEED_AP_MLME
1237 struct wpa_supplicant *wpa_s = ctx;
1238 struct hostapd_frame_info fi;
1239 os_memset(&fi, 0, sizeof(fi));
1240 fi.freq = rx_mgmt->freq;
1241 fi.datarate = rx_mgmt->datarate;
1242 fi.ssi_signal = rx_mgmt->ssi_signal;
1243 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1244 rx_mgmt->frame_len, &fi);
1245#endif /* NEED_AP_MLME */
1246}
1247
1248
1249void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1250{
1251#ifdef NEED_AP_MLME
1252 struct wpa_supplicant *wpa_s = ctx;
1253 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1254#endif /* NEED_AP_MLME */
1255}
1256
1257
1258void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1259 const u8 *src_addr, const u8 *buf, size_t len,
1260 enum frame_encryption encrypted)
1261{
1262 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len,
1263 encrypted);
1264}
1265
1266
1267#ifdef CONFIG_WPS
1268
1269int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1270 const u8 *p2p_dev_addr)
1271{
1272 if (!wpa_s->ap_iface)
1273 return -1;
1274 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1275 p2p_dev_addr);
1276}
1277
1278
1279int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1280{
1281 struct wps_registrar *reg;
1282 int reg_sel = 0, wps_sta = 0;
1283
1284 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1285 return -1;
1286
1287 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1288 reg_sel = wps_registrar_wps_cancel(reg);
1289 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
1290 ap_sta_wps_cancel, NULL);
1291
1292 if (!reg_sel && !wps_sta) {
1293 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1294 "time");
1295 return -1;
1296 }
1297
1298 /*
1299 * There are 2 cases to return wps cancel as success:
1300 * 1. When wps cancel was initiated but no connection has been
1301 * established with client yet.
1302 * 2. Client is in the middle of exchanging WPS messages.
1303 */
1304
1305 return 0;
1306}
1307
1308
1309int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
1310 const char *pin, char *buf, size_t buflen,
1311 int timeout)
1312{
1313 int ret, ret_len = 0;
1314
1315 if (!wpa_s->ap_iface)
1316 return -1;
1317
1318 if (pin == NULL) {
1319 unsigned int rpin;
1320
1321 if (wps_generate_pin(&rpin) < 0)
1322 return -1;
1323 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
1324 if (os_snprintf_error(buflen, ret_len))
1325 return -1;
1326 pin = buf;
1327 } else if (buf) {
1328 ret_len = os_snprintf(buf, buflen, "%s", pin);
1329 if (os_snprintf_error(buflen, ret_len))
1330 return -1;
1331 }
1332
1333 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
1334 timeout);
1335 if (ret)
1336 return -1;
1337 return ret_len;
1338}
1339
1340
1341static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1342{
1343 struct wpa_supplicant *wpa_s = eloop_data;
1344 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1345 wpas_wps_ap_pin_disable(wpa_s);
1346}
1347
1348
1349static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1350{
1351 struct hostapd_data *hapd;
1352
1353 if (wpa_s->ap_iface == NULL)
1354 return;
1355 hapd = wpa_s->ap_iface->bss[0];
1356 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1357 hapd->ap_pin_failures = 0;
1358 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1359 if (timeout > 0)
1360 eloop_register_timeout(timeout, 0,
1361 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1362}
1363
1364
1365void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1366{
1367 struct hostapd_data *hapd;
1368
1369 if (wpa_s->ap_iface == NULL)
1370 return;
1371 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1372 hapd = wpa_s->ap_iface->bss[0];
1373 os_free(hapd->conf->ap_pin);
1374 hapd->conf->ap_pin = NULL;
1375 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1376}
1377
1378
1379const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1380{
1381 struct hostapd_data *hapd;
1382 unsigned int pin;
1383 char pin_txt[9];
1384
1385 if (wpa_s->ap_iface == NULL)
1386 return NULL;
1387 hapd = wpa_s->ap_iface->bss[0];
1388 if (wps_generate_pin(&pin) < 0)
1389 return NULL;
1390 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
1391 os_free(hapd->conf->ap_pin);
1392 hapd->conf->ap_pin = os_strdup(pin_txt);
1393 if (hapd->conf->ap_pin == NULL)
1394 return NULL;
1395 wpas_wps_ap_pin_enable(wpa_s, timeout);
1396
1397 return hapd->conf->ap_pin;
1398}
1399
1400
1401const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1402{
1403 struct hostapd_data *hapd;
1404 if (wpa_s->ap_iface == NULL)
1405 return NULL;
1406 hapd = wpa_s->ap_iface->bss[0];
1407 return hapd->conf->ap_pin;
1408}
1409
1410
1411int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1412 int timeout)
1413{
1414 struct hostapd_data *hapd;
1415 char pin_txt[9];
1416 int ret;
1417
1418 if (wpa_s->ap_iface == NULL)
1419 return -1;
1420 hapd = wpa_s->ap_iface->bss[0];
1421 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
1422 if (os_snprintf_error(sizeof(pin_txt), ret))
1423 return -1;
1424 os_free(hapd->conf->ap_pin);
1425 hapd->conf->ap_pin = os_strdup(pin_txt);
1426 if (hapd->conf->ap_pin == NULL)
1427 return -1;
1428 wpas_wps_ap_pin_enable(wpa_s, timeout);
1429
1430 return 0;
1431}
1432
1433
1434void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1435{
1436 struct hostapd_data *hapd;
1437
1438 if (wpa_s->ap_iface == NULL)
1439 return;
1440 hapd = wpa_s->ap_iface->bss[0];
1441
1442 /*
1443 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1444 * PIN if this happens multiple times to slow down brute force attacks.
1445 */
1446 hapd->ap_pin_failures++;
1447 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1448 hapd->ap_pin_failures);
1449 if (hapd->ap_pin_failures < 3)
1450 return;
1451
1452 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1453 hapd->ap_pin_failures = 0;
1454 os_free(hapd->conf->ap_pin);
1455 hapd->conf->ap_pin = NULL;
1456}
1457
1458
1459#ifdef CONFIG_WPS_NFC
1460
1461struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1462 int ndef)
1463{
1464 struct hostapd_data *hapd;
1465
1466 if (wpa_s->ap_iface == NULL)
1467 return NULL;
1468 hapd = wpa_s->ap_iface->bss[0];
1469 return hostapd_wps_nfc_config_token(hapd, ndef);
1470}
1471
1472
1473struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1474 int ndef)
1475{
1476 struct hostapd_data *hapd;
1477
1478 if (wpa_s->ap_iface == NULL)
1479 return NULL;
1480 hapd = wpa_s->ap_iface->bss[0];
1481 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1482}
1483
1484
1485int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1486 const struct wpabuf *req,
1487 const struct wpabuf *sel)
1488{
1489 struct hostapd_data *hapd;
1490
1491 if (wpa_s->ap_iface == NULL)
1492 return -1;
1493 hapd = wpa_s->ap_iface->bss[0];
1494 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1495}
1496
1497#endif /* CONFIG_WPS_NFC */
1498
1499#endif /* CONFIG_WPS */
1500
1501
1502#if defined(CONFIG_CTRL_IFACE) && defined(CONFIG_CTRL_IFACE_MIB)
1503
1504int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1505 char *buf, size_t buflen)
1506{
1507 struct hostapd_data *hapd;
1508
1509 if (wpa_s->ap_iface)
1510 hapd = wpa_s->ap_iface->bss[0];
1511 else if (wpa_s->ifmsh)
1512 hapd = wpa_s->ifmsh->bss[0];
1513 else
1514 return -1;
1515 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
1516}
1517
1518
1519int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1520 char *buf, size_t buflen)
1521{
1522 struct hostapd_data *hapd;
1523
1524 if (wpa_s->ap_iface)
1525 hapd = wpa_s->ap_iface->bss[0];
1526 else if (wpa_s->ifmsh)
1527 hapd = wpa_s->ifmsh->bss[0];
1528 else
1529 return -1;
1530 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
1531}
1532
1533
1534int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1535 char *buf, size_t buflen)
1536{
1537 struct hostapd_data *hapd;
1538
1539 if (wpa_s->ap_iface)
1540 hapd = wpa_s->ap_iface->bss[0];
1541 else if (wpa_s->ifmsh)
1542 hapd = wpa_s->ifmsh->bss[0];
1543 else
1544 return -1;
1545 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
1546}
1547
1548
1549int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1550 const char *txtaddr)
1551{
1552 if (wpa_s->ap_iface == NULL)
1553 return -1;
1554 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1555 txtaddr);
1556}
1557
1558
1559int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1560 const char *txtaddr)
1561{
1562 if (wpa_s->ap_iface == NULL)
1563 return -1;
1564 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1565 txtaddr);
1566}
1567
1568
1569int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1570 size_t buflen, int verbose)
1571{
1572 char *pos = buf, *end = buf + buflen;
1573 int ret;
1574 struct hostapd_bss_config *conf;
1575
1576 if (wpa_s->ap_iface == NULL)
1577 return -1;
1578
1579 conf = wpa_s->ap_iface->bss[0]->conf;
1580 if (conf->wpa == 0)
1581 return 0;
1582
1583 ret = os_snprintf(pos, end - pos,
1584 "pairwise_cipher=%s\n"
1585 "group_cipher=%s\n"
1586 "key_mgmt=%s\n",
1587 wpa_cipher_txt(conf->rsn_pairwise),
1588 wpa_cipher_txt(conf->wpa_group),
1589 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1590 conf->wpa));
1591 if (os_snprintf_error(end - pos, ret))
1592 return pos - buf;
1593 pos += ret;
1594 return pos - buf;
1595}
1596
1597
1598#ifdef CONFIG_WNM_AP
1599
1600int ap_ctrl_iface_disassoc_imminent(struct wpa_supplicant *wpa_s,
1601 const char *buf)
1602{
1603 struct hostapd_data *hapd;
1604
1605 if (wpa_s->ap_iface)
1606 hapd = wpa_s->ap_iface->bss[0];
1607 else
1608 return -1;
1609 return hostapd_ctrl_iface_disassoc_imminent(hapd, buf);
1610}
1611
1612
1613int ap_ctrl_iface_ess_disassoc(struct wpa_supplicant *wpa_s, const char *buf)
1614{
1615 struct hostapd_data *hapd;
1616
1617 if (wpa_s->ap_iface)
1618 hapd = wpa_s->ap_iface->bss[0];
1619 else
1620 return -1;
1621 return hostapd_ctrl_iface_ess_disassoc(hapd, buf);
1622}
1623
1624
1625int ap_ctrl_iface_bss_tm_req(struct wpa_supplicant *wpa_s, const char *buf)
1626{
1627 struct hostapd_data *hapd;
1628
1629 if (wpa_s->ap_iface)
1630 hapd = wpa_s->ap_iface->bss[0];
1631 else
1632 return -1;
1633 return hostapd_ctrl_iface_bss_tm_req(hapd, buf);
1634}
1635
1636#endif /* CONFIG_WNM_AP */
1637
1638
1639int ap_ctrl_iface_acl_add_mac(struct wpa_supplicant *wpa_s,
1640 enum macaddr_acl acl_type,
1641 const char *buf)
1642{
1643 struct hostapd_data *hapd;
1644
1645 if (wpa_s->ap_iface)
1646 hapd = wpa_s->ap_iface->bss[0];
1647 else
1648 return -1;
1649
1650 hapd->conf->macaddr_acl = acl_type;
1651
1652 if (acl_type == ACCEPT_UNLESS_DENIED)
1653 return hostapd_ctrl_iface_acl_add_mac(&hapd->conf->deny_mac,
1654 &hapd->conf->num_deny_mac,
1655 buf);
1656 if (acl_type == DENY_UNLESS_ACCEPTED)
1657 return hostapd_ctrl_iface_acl_add_mac(
1658 &hapd->conf->accept_mac,
1659 &hapd->conf->num_accept_mac, buf);
1660
1661 return -1;
1662}
1663
1664
1665int ap_ctrl_iface_acl_del_mac(struct wpa_supplicant *wpa_s,
1666 enum macaddr_acl acl_type,
1667 const char *buf)
1668{
1669 struct hostapd_data *hapd;
1670
1671 if (wpa_s->ap_iface)
1672 hapd = wpa_s->ap_iface->bss[0];
1673 else
1674 return -1;
1675
1676 hapd->conf->macaddr_acl = acl_type;
1677
1678 if (acl_type == ACCEPT_UNLESS_DENIED)
1679 return hostapd_ctrl_iface_acl_del_mac(&hapd->conf->deny_mac,
1680 &hapd->conf->num_deny_mac,
1681 buf);
1682 if (acl_type == DENY_UNLESS_ACCEPTED)
1683 return hostapd_ctrl_iface_acl_del_mac(
1684 &hapd->conf->accept_mac, &hapd->conf->num_accept_mac,
1685 buf);
1686
1687 return -1;
1688}
1689
1690
1691int ap_ctrl_iface_acl_show_mac(struct wpa_supplicant *wpa_s,
1692 enum macaddr_acl acl_type, char *buf,
1693 size_t buflen)
1694{
1695 struct hostapd_data *hapd;
1696
1697 if (wpa_s->ap_iface)
1698 hapd = wpa_s->ap_iface->bss[0];
1699 else
1700 return -1;
1701
1702 if (acl_type == ACCEPT_UNLESS_DENIED)
1703 return hostapd_ctrl_iface_acl_show_mac(hapd->conf->deny_mac,
1704 hapd->conf->num_deny_mac,
1705 buf, buflen);
1706 if (acl_type == DENY_UNLESS_ACCEPTED)
1707 return hostapd_ctrl_iface_acl_show_mac(
1708 hapd->conf->accept_mac, hapd->conf->num_accept_mac,
1709 buf, buflen);
1710
1711 return -1;
1712}
1713
1714
1715void ap_ctrl_iface_acl_clear_list(struct wpa_supplicant *wpa_s,
1716 enum macaddr_acl acl_type)
1717{
1718 struct hostapd_data *hapd;
1719
1720 if (wpa_s->ap_iface)
1721 hapd = wpa_s->ap_iface->bss[0];
1722 else
1723 return;
1724
1725 hapd->conf->macaddr_acl = acl_type;
1726
1727 if (acl_type == ACCEPT_UNLESS_DENIED)
1728 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->deny_mac,
1729 &hapd->conf->num_deny_mac);
1730 else if (acl_type == DENY_UNLESS_ACCEPTED)
1731 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->accept_mac,
1732 &hapd->conf->num_accept_mac);
1733}
1734
1735
1736int ap_ctrl_iface_disassoc_deny_mac(struct wpa_supplicant *wpa_s)
1737{
1738 struct hostapd_data *hapd;
1739
1740 if (wpa_s->ap_iface)
1741 hapd = wpa_s->ap_iface->bss[0];
1742 else
1743 return -1;
1744
1745 return hostapd_disassoc_deny_mac(hapd);
1746}
1747
1748
1749int ap_ctrl_iface_disassoc_accept_mac(struct wpa_supplicant *wpa_s)
1750{
1751 struct hostapd_data *hapd;
1752
1753 if (wpa_s->ap_iface)
1754 hapd = wpa_s->ap_iface->bss[0];
1755 else
1756 return -1;
1757
1758 return hostapd_disassoc_accept_mac(hapd);
1759}
1760
1761
1762int ap_ctrl_iface_set_acl(struct wpa_supplicant *wpa_s)
1763{
1764 struct hostapd_data *hapd;
1765
1766 if (wpa_s->ap_iface)
1767 hapd = wpa_s->ap_iface->bss[0];
1768 else
1769 return -1;
1770
1771 return hostapd_set_acl(hapd);
1772}
1773
1774#endif /* CONFIG_CTRL_IFACE */
1775
1776
1777int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1778{
1779 struct hostapd_iface *iface = wpa_s->ap_iface;
1780 struct wpa_ssid *ssid = wpa_s->current_ssid;
1781 struct hostapd_data *hapd;
1782
1783 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1784 ssid->mode == WPAS_MODE_INFRA ||
1785 ssid->mode == WPAS_MODE_IBSS)
1786 return -1;
1787
1788#ifdef CONFIG_P2P
1789 if (ssid->mode == WPAS_MODE_P2P_GO)
1790 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
1791 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1792 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
1793 P2P_GROUP_FORMATION;
1794#endif /* CONFIG_P2P */
1795
1796 hapd = iface->bss[0];
1797 if (hapd->drv_priv == NULL)
1798 return -1;
1799 ieee802_11_set_beacons(iface);
1800 hostapd_set_ap_wps_ie(hapd);
1801
1802 return 0;
1803}
1804
1805
1806int ap_switch_channel(struct wpa_supplicant *wpa_s,
1807 struct csa_settings *settings)
1808{
1809#ifdef NEED_AP_MLME
1810 struct hostapd_iface *iface = NULL;
1811
1812 if (wpa_s->ap_iface)
1813 iface = wpa_s->ap_iface;
1814 else if (wpa_s->ifmsh)
1815 iface = wpa_s->ifmsh;
1816
1817 if (!iface || !iface->bss[0])
1818 return -1;
1819
1820 return hostapd_switch_channel(iface->bss[0], settings);
1821#else /* NEED_AP_MLME */
1822 return -1;
1823#endif /* NEED_AP_MLME */
1824}
1825
1826
1827#ifdef CONFIG_CTRL_IFACE
1828
1829static int __ap_ctrl_iface_chanswitch(struct hostapd_iface *iface,
1830 struct csa_settings *settings)
1831{
1832#ifdef NEED_AP_MLME
1833 if (!iface || !iface->bss[0])
1834 return 0;
1835
1836 return hostapd_switch_channel(iface->bss[0], settings);
1837#else
1838 return -1;
1839#endif
1840}
1841
1842
1843int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1844{
1845 struct csa_settings settings;
1846 int ret = hostapd_parse_csa_settings(pos, &settings);
1847
1848 if (!(wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) &&
1849 !(wpa_s->ifmsh && wpa_s->ifmsh->bss[0]))
1850 return -1;
1851
1852 ret = __ap_ctrl_iface_chanswitch(wpa_s->ap_iface, &settings);
1853 if (ret)
1854 return ret;
1855
1856 return __ap_ctrl_iface_chanswitch(wpa_s->ifmsh, &settings);
1857}
1858#endif /* CONFIG_CTRL_IFACE */
1859
1860
1861void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
1862 int offset, int width, int cf1, int cf2,
1863 u16 punct_bitmap, int finished)
1864{
1865 struct hostapd_iface *iface = wpa_s->ap_iface;
1866
1867 if (!iface)
1868 iface = wpa_s->ifmsh;
1869 if (!iface)
1870 return;
1871 wpa_s->assoc_freq = freq;
1872 if (wpa_s->current_ssid)
1873 wpa_s->current_ssid->frequency = freq;
1874 hostapd_event_ch_switch(iface->bss[0], freq, ht,
1875 offset, width, cf1, cf2, punct_bitmap,
1876 finished);
1877}
1878
1879
1880int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1881 const u8 *addr)
1882{
1883 struct hostapd_data *hapd;
1884 struct hostapd_bss_config *conf;
1885
1886 if (!wpa_s->ap_iface)
1887 return -1;
1888
1889 if (addr)
1890 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1891 MAC2STR(addr));
1892 else
1893 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1894
1895 hapd = wpa_s->ap_iface->bss[0];
1896 conf = hapd->conf;
1897
1898 os_free(conf->accept_mac);
1899 conf->accept_mac = NULL;
1900 conf->num_accept_mac = 0;
1901 os_free(conf->deny_mac);
1902 conf->deny_mac = NULL;
1903 conf->num_deny_mac = 0;
1904
1905 if (addr == NULL) {
1906 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1907 return 0;
1908 }
1909
1910 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1911 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1912 if (conf->accept_mac == NULL)
1913 return -1;
1914 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1915 conf->num_accept_mac = 1;
1916
1917 return 0;
1918}
1919
1920
1921#ifdef CONFIG_WPS_NFC
1922int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1923 const struct wpabuf *pw, const u8 *pubkey_hash)
1924{
1925 struct hostapd_data *hapd;
1926 struct wps_context *wps;
1927
1928 if (!wpa_s->ap_iface)
1929 return -1;
1930 hapd = wpa_s->ap_iface->bss[0];
1931 wps = hapd->wps;
1932
1933 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1934 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
1935 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1936 return -1;
1937 }
1938
1939 dh5_free(wps->dh_ctx);
1940 wpabuf_free(wps->dh_pubkey);
1941 wpabuf_free(wps->dh_privkey);
1942 wps->dh_privkey = wpabuf_dup(
1943 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
1944 wps->dh_pubkey = wpabuf_dup(
1945 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
1946 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1947 wps->dh_ctx = NULL;
1948 wpabuf_free(wps->dh_pubkey);
1949 wps->dh_pubkey = NULL;
1950 wpabuf_free(wps->dh_privkey);
1951 wps->dh_privkey = NULL;
1952 return -1;
1953 }
1954 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1955 if (wps->dh_ctx == NULL)
1956 return -1;
1957
1958 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1959 pw_id,
1960 pw ? wpabuf_head(pw) : NULL,
1961 pw ? wpabuf_len(pw) : 0, 1);
1962}
1963#endif /* CONFIG_WPS_NFC */
1964
1965
1966#ifdef CONFIG_CTRL_IFACE
1967int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1968{
1969 struct hostapd_data *hapd;
1970
1971 if (!wpa_s->ap_iface)
1972 return -1;
1973 hapd = wpa_s->ap_iface->bss[0];
1974 return hostapd_ctrl_iface_stop_ap(hapd);
1975}
1976
1977
1978int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1979 size_t len)
1980{
1981 size_t reply_len = 0, i;
1982 char ap_delimiter[] = "---- AP ----\n";
1983 char mesh_delimiter[] = "---- mesh ----\n";
1984 size_t dlen;
1985
1986 if (wpa_s->ap_iface) {
1987 dlen = os_strlen(ap_delimiter);
1988 if (dlen > len - reply_len)
1989 return reply_len;
1990 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1991 reply_len += dlen;
1992
1993 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1994 reply_len += hostapd_ctrl_iface_pmksa_list(
1995 wpa_s->ap_iface->bss[i],
1996 &buf[reply_len], len - reply_len);
1997 }
1998 }
1999
2000 if (wpa_s->ifmsh) {
2001 dlen = os_strlen(mesh_delimiter);
2002 if (dlen > len - reply_len)
2003 return reply_len;
2004 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
2005 reply_len += dlen;
2006
2007 reply_len += hostapd_ctrl_iface_pmksa_list(
2008 wpa_s->ifmsh->bss[0], &buf[reply_len],
2009 len - reply_len);
2010 }
2011
2012 return reply_len;
2013}
2014
2015
2016void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
2017{
2018 size_t i;
2019
2020 if (wpa_s->ap_iface) {
2021 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
2022 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
2023 }
2024
2025 if (wpa_s->ifmsh)
2026 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
2027}
2028
2029
2030#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
2031#ifdef CONFIG_MESH
2032
2033int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
2034 char *buf, size_t len)
2035{
2036 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
2037 &buf[0], len);
2038}
2039
2040
2041int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
2042{
2043 struct external_pmksa_cache *entry;
2044 void *pmksa_cache;
2045
2046 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
2047 cmd);
2048 if (!pmksa_cache)
2049 return -1;
2050
2051 entry = os_zalloc(sizeof(struct external_pmksa_cache));
2052 if (!entry)
2053 return -1;
2054
2055 entry->pmksa_cache = pmksa_cache;
2056
2057 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
2058
2059 return 0;
2060}
2061
2062#endif /* CONFIG_MESH */
2063#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
2064
2065
2066int wpas_ap_update_beacon(struct wpa_supplicant *wpa_s)
2067{
2068 struct hostapd_data *hapd;
2069
2070 if (!wpa_s->ap_iface)
2071 return -1;
2072 hapd = wpa_s->ap_iface->bss[0];
2073
2074 wpabuf_free(hapd->conf->assocresp_elements);
2075 hapd->conf->assocresp_elements = NULL;
2076 if (wpa_s->conf->ap_assocresp_elements) {
2077 hapd->conf->assocresp_elements =
2078 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
2079 }
2080
2081 wpabuf_free(hapd->conf->vendor_elements);
2082 hapd->conf->vendor_elements = NULL;
2083 if (wpa_s->conf->ap_vendor_elements) {
2084 hapd->conf->vendor_elements =
2085 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
2086 }
2087
2088 return ieee802_11_set_beacon(hapd);
2089}
2090
2091#endif /* CONFIG_CTRL_IFACE */
2092
2093
2094#ifdef NEED_AP_MLME
2095void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
2096 struct dfs_event *radar)
2097{
2098 struct hostapd_iface *iface = wpa_s->ap_iface;
2099
2100 if (!iface)
2101 iface = wpa_s->ifmsh;
2102 if (!iface || !iface->bss[0])
2103 return;
2104 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
2105 hostapd_dfs_radar_detected(iface, radar->freq,
2106 radar->ht_enabled, radar->chan_offset,
2107 radar->chan_width,
2108 radar->cf1, radar->cf2);
2109}
2110
2111
2112void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
2113 struct dfs_event *radar)
2114{
2115 struct hostapd_iface *iface = wpa_s->ap_iface;
2116
2117 if (!iface)
2118 iface = wpa_s->ifmsh;
2119 if (!iface || !iface->bss[0])
2120 return;
2121 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
2122 hostapd_dfs_start_cac(iface, radar->freq,
2123 radar->ht_enabled, radar->chan_offset,
2124 radar->chan_width, radar->cf1, radar->cf2);
2125}
2126
2127
2128void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
2129 struct dfs_event *radar)
2130{
2131 struct hostapd_iface *iface = wpa_s->ap_iface;
2132
2133 if (!iface)
2134 iface = wpa_s->ifmsh;
2135 if (!iface || !iface->bss[0])
2136 return;
2137 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
2138 hostapd_dfs_complete_cac(iface, 1, radar->freq,
2139 radar->ht_enabled, radar->chan_offset,
2140 radar->chan_width, radar->cf1, radar->cf2);
2141}
2142
2143
2144void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
2145 struct dfs_event *radar)
2146{
2147 struct hostapd_iface *iface = wpa_s->ap_iface;
2148
2149 if (!iface)
2150 iface = wpa_s->ifmsh;
2151 if (!iface || !iface->bss[0])
2152 return;
2153 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
2154 hostapd_dfs_complete_cac(iface, 0, radar->freq,
2155 radar->ht_enabled, radar->chan_offset,
2156 radar->chan_width, radar->cf1, radar->cf2);
2157}
2158
2159
2160void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
2161 struct dfs_event *radar)
2162{
2163 struct hostapd_iface *iface = wpa_s->ap_iface;
2164
2165 if (!iface)
2166 iface = wpa_s->ifmsh;
2167 if (!iface || !iface->bss[0])
2168 return;
2169 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
2170 hostapd_dfs_nop_finished(iface, radar->freq,
2171 radar->ht_enabled, radar->chan_offset,
2172 radar->chan_width, radar->cf1, radar->cf2);
2173}
2174#endif /* NEED_AP_MLME */
2175
2176
2177void ap_periodic(struct wpa_supplicant *wpa_s)
2178{
2179 if (wpa_s->ap_iface)
2180 hostapd_periodic_iface(wpa_s->ap_iface);
2181}