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