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