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