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