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