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