ap_drv_ops.c revision cce06667447b5aec83452adb0c15100ada531095
1/* 2 * hostapd - Driver operations 3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9#include "utils/includes.h" 10 11#include "utils/common.h" 12#include "drivers/driver.h" 13#include "common/ieee802_11_defs.h" 14#include "wps/wps.h" 15#include "p2p/p2p.h" 16#include "hostapd.h" 17#include "ieee802_11.h" 18#include "sta_info.h" 19#include "ap_config.h" 20#include "p2p_hostapd.h" 21#include "hs20.h" 22#include "ap_drv_ops.h" 23 24 25u32 hostapd_sta_flags_to_drv(u32 flags) 26{ 27 int res = 0; 28 if (flags & WLAN_STA_AUTHORIZED) 29 res |= WPA_STA_AUTHORIZED; 30 if (flags & WLAN_STA_WMM) 31 res |= WPA_STA_WMM; 32 if (flags & WLAN_STA_SHORT_PREAMBLE) 33 res |= WPA_STA_SHORT_PREAMBLE; 34 if (flags & WLAN_STA_MFP) 35 res |= WPA_STA_MFP; 36 return res; 37} 38 39 40int hostapd_build_ap_extra_ies(struct hostapd_data *hapd, 41 struct wpabuf **beacon_ret, 42 struct wpabuf **proberesp_ret, 43 struct wpabuf **assocresp_ret) 44{ 45 struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL; 46 u8 buf[200], *pos; 47 48 *beacon_ret = *proberesp_ret = *assocresp_ret = NULL; 49 50 pos = buf; 51 pos = hostapd_eid_time_adv(hapd, pos); 52 if (pos != buf) { 53 if (wpabuf_resize(&beacon, pos - buf) != 0) 54 goto fail; 55 wpabuf_put_data(beacon, buf, pos - buf); 56 } 57 pos = hostapd_eid_time_zone(hapd, pos); 58 if (pos != buf) { 59 if (wpabuf_resize(&proberesp, pos - buf) != 0) 60 goto fail; 61 wpabuf_put_data(proberesp, buf, pos - buf); 62 } 63 64 pos = buf; 65 pos = hostapd_eid_ext_capab(hapd, pos); 66 if (pos != buf) { 67 if (wpabuf_resize(&assocresp, pos - buf) != 0) 68 goto fail; 69 wpabuf_put_data(assocresp, buf, pos - buf); 70 } 71 pos = hostapd_eid_interworking(hapd, pos); 72 pos = hostapd_eid_adv_proto(hapd, pos); 73 pos = hostapd_eid_roaming_consortium(hapd, pos); 74 if (pos != buf) { 75 if (wpabuf_resize(&beacon, pos - buf) != 0) 76 goto fail; 77 wpabuf_put_data(beacon, buf, pos - buf); 78 79 if (wpabuf_resize(&proberesp, pos - buf) != 0) 80 goto fail; 81 wpabuf_put_data(proberesp, buf, pos - buf); 82 } 83 84 if (hapd->wps_beacon_ie) { 85 if (wpabuf_resize(&beacon, wpabuf_len(hapd->wps_beacon_ie)) < 86 0) 87 goto fail; 88 wpabuf_put_buf(beacon, hapd->wps_beacon_ie); 89 } 90 91 if (hapd->wps_probe_resp_ie) { 92 if (wpabuf_resize(&proberesp, 93 wpabuf_len(hapd->wps_probe_resp_ie)) < 0) 94 goto fail; 95 wpabuf_put_buf(proberesp, hapd->wps_probe_resp_ie); 96 } 97 98#ifdef CONFIG_P2P 99 if (hapd->p2p_beacon_ie) { 100 if (wpabuf_resize(&beacon, wpabuf_len(hapd->p2p_beacon_ie)) < 101 0) 102 goto fail; 103 wpabuf_put_buf(beacon, hapd->p2p_beacon_ie); 104 } 105 106 if (hapd->p2p_probe_resp_ie) { 107 if (wpabuf_resize(&proberesp, 108 wpabuf_len(hapd->p2p_probe_resp_ie)) < 0) 109 goto fail; 110 wpabuf_put_buf(proberesp, hapd->p2p_probe_resp_ie); 111 } 112#endif /* CONFIG_P2P */ 113 114#ifdef CONFIG_P2P_MANAGER 115 if (hapd->conf->p2p & P2P_MANAGE) { 116 if (wpabuf_resize(&beacon, 100) == 0) { 117 u8 *start, *p; 118 start = wpabuf_put(beacon, 0); 119 p = hostapd_eid_p2p_manage(hapd, start); 120 wpabuf_put(beacon, p - start); 121 } 122 123 if (wpabuf_resize(&proberesp, 100) == 0) { 124 u8 *start, *p; 125 start = wpabuf_put(proberesp, 0); 126 p = hostapd_eid_p2p_manage(hapd, start); 127 wpabuf_put(proberesp, p - start); 128 } 129 } 130#endif /* CONFIG_P2P_MANAGER */ 131 132#ifdef CONFIG_WPS2 133 if (hapd->conf->wps_state) { 134 struct wpabuf *a = wps_build_assoc_resp_ie(); 135 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0) 136 wpabuf_put_buf(assocresp, a); 137 wpabuf_free(a); 138 } 139#endif /* CONFIG_WPS2 */ 140 141#ifdef CONFIG_P2P_MANAGER 142 if (hapd->conf->p2p & P2P_MANAGE) { 143 if (wpabuf_resize(&assocresp, 100) == 0) { 144 u8 *start, *p; 145 start = wpabuf_put(assocresp, 0); 146 p = hostapd_eid_p2p_manage(hapd, start); 147 wpabuf_put(assocresp, p - start); 148 } 149 } 150#endif /* CONFIG_P2P_MANAGER */ 151 152#ifdef CONFIG_WIFI_DISPLAY 153 if (hapd->p2p_group) { 154 struct wpabuf *a; 155 a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS); 156 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0) 157 wpabuf_put_buf(assocresp, a); 158 wpabuf_free(a); 159 } 160#endif /* CONFIG_WIFI_DISPLAY */ 161 162#ifdef CONFIG_HS20 163 pos = buf; 164 pos = hostapd_eid_hs20_indication(hapd, pos); 165 if (pos != buf) { 166 if (wpabuf_resize(&beacon, pos - buf) != 0) 167 goto fail; 168 wpabuf_put_data(beacon, buf, pos - buf); 169 170 if (wpabuf_resize(&proberesp, pos - buf) != 0) 171 goto fail; 172 wpabuf_put_data(proberesp, buf, pos - buf); 173 } 174#endif /* CONFIG_HS20 */ 175 176 if (hapd->conf->vendor_elements) { 177 size_t add = wpabuf_len(hapd->conf->vendor_elements); 178 if (wpabuf_resize(&beacon, add) == 0) 179 wpabuf_put_buf(beacon, hapd->conf->vendor_elements); 180 if (wpabuf_resize(&proberesp, add) == 0) 181 wpabuf_put_buf(proberesp, hapd->conf->vendor_elements); 182 } 183 184 *beacon_ret = beacon; 185 *proberesp_ret = proberesp; 186 *assocresp_ret = assocresp; 187 188 return 0; 189 190fail: 191 wpabuf_free(beacon); 192 wpabuf_free(proberesp); 193 wpabuf_free(assocresp); 194 return -1; 195} 196 197 198void hostapd_free_ap_extra_ies(struct hostapd_data *hapd, 199 struct wpabuf *beacon, 200 struct wpabuf *proberesp, 201 struct wpabuf *assocresp) 202{ 203 wpabuf_free(beacon); 204 wpabuf_free(proberesp); 205 wpabuf_free(assocresp); 206} 207 208 209int hostapd_set_ap_wps_ie(struct hostapd_data *hapd) 210{ 211 struct wpabuf *beacon, *proberesp, *assocresp; 212 int ret; 213 214 if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL) 215 return 0; 216 217 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < 218 0) 219 return -1; 220 221 ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp, 222 assocresp); 223 224 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); 225 226 return ret; 227} 228 229 230int hostapd_set_authorized(struct hostapd_data *hapd, 231 struct sta_info *sta, int authorized) 232{ 233 if (authorized) { 234 return hostapd_sta_set_flags(hapd, sta->addr, 235 hostapd_sta_flags_to_drv( 236 sta->flags), 237 WPA_STA_AUTHORIZED, ~0); 238 } 239 240 return hostapd_sta_set_flags(hapd, sta->addr, 241 hostapd_sta_flags_to_drv(sta->flags), 242 0, ~WPA_STA_AUTHORIZED); 243} 244 245 246int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta) 247{ 248 int set_flags, total_flags, flags_and, flags_or; 249 total_flags = hostapd_sta_flags_to_drv(sta->flags); 250 set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP; 251 if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) || 252 sta->auth_alg == WLAN_AUTH_FT) && 253 sta->flags & WLAN_STA_AUTHORIZED) 254 set_flags |= WPA_STA_AUTHORIZED; 255 flags_or = total_flags & set_flags; 256 flags_and = total_flags | ~set_flags; 257 return hostapd_sta_set_flags(hapd, sta->addr, total_flags, 258 flags_or, flags_and); 259} 260 261 262int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname, 263 int enabled) 264{ 265 struct wpa_bss_params params; 266 os_memset(¶ms, 0, sizeof(params)); 267 params.ifname = ifname; 268 params.enabled = enabled; 269 if (enabled) { 270 params.wpa = hapd->conf->wpa; 271 params.ieee802_1x = hapd->conf->ieee802_1x; 272 params.wpa_group = hapd->conf->wpa_group; 273 params.wpa_pairwise = hapd->conf->wpa_pairwise; 274 params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt; 275 params.rsn_preauth = hapd->conf->rsn_preauth; 276#ifdef CONFIG_IEEE80211W 277 params.ieee80211w = hapd->conf->ieee80211w; 278#endif /* CONFIG_IEEE80211W */ 279 } 280 return hostapd_set_ieee8021x(hapd, ¶ms); 281} 282 283 284int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname) 285{ 286 char force_ifname[IFNAMSIZ]; 287 u8 if_addr[ETH_ALEN]; 288 return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr, 289 NULL, NULL, force_ifname, if_addr, NULL, 0); 290} 291 292 293int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname) 294{ 295 return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname); 296} 297 298 299int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds, 300 const u8 *addr, int aid, int val) 301{ 302 const char *bridge = NULL; 303 304 if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL) 305 return -1; 306 if (hapd->conf->wds_bridge[0]) 307 bridge = hapd->conf->wds_bridge; 308 else if (hapd->conf->bridge[0]) 309 bridge = hapd->conf->bridge; 310 return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val, 311 bridge, ifname_wds); 312} 313 314 315int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr, 316 u16 auth_alg) 317{ 318 if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL) 319 return 0; 320 return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg); 321} 322 323 324int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr, 325 u16 seq, u16 status, const u8 *ie, size_t len) 326{ 327 if (hapd->driver == NULL || hapd->driver->sta_auth == NULL) 328 return 0; 329 return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr, 330 seq, status, ie, len); 331} 332 333 334int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr, 335 int reassoc, u16 status, const u8 *ie, size_t len) 336{ 337 if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL) 338 return 0; 339 return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr, 340 reassoc, status, ie, len); 341} 342 343 344int hostapd_sta_add(struct hostapd_data *hapd, 345 const u8 *addr, u16 aid, u16 capability, 346 const u8 *supp_rates, size_t supp_rates_len, 347 u16 listen_interval, 348 const struct ieee80211_ht_capabilities *ht_capab, 349 const struct ieee80211_vht_capabilities *vht_capab, 350 u32 flags, u8 qosinfo) 351{ 352 struct hostapd_sta_add_params params; 353 354 if (hapd->driver == NULL) 355 return 0; 356 if (hapd->driver->sta_add == NULL) 357 return 0; 358 359 os_memset(¶ms, 0, sizeof(params)); 360 params.addr = addr; 361 params.aid = aid; 362 params.capability = capability; 363 params.supp_rates = supp_rates; 364 params.supp_rates_len = supp_rates_len; 365 params.listen_interval = listen_interval; 366 params.ht_capabilities = ht_capab; 367 params.vht_capabilities = vht_capab; 368 params.flags = hostapd_sta_flags_to_drv(flags); 369 params.qosinfo = qosinfo; 370 return hapd->driver->sta_add(hapd->drv_priv, ¶ms); 371} 372 373 374int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr, 375 u8 *tspec_ie, size_t tspec_ielen) 376{ 377 if (hapd->driver == NULL || hapd->driver->add_tspec == NULL) 378 return 0; 379 return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie, 380 tspec_ielen); 381} 382 383 384int hostapd_set_privacy(struct hostapd_data *hapd, int enabled) 385{ 386 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL) 387 return 0; 388 return hapd->driver->set_privacy(hapd->drv_priv, enabled); 389} 390 391 392int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem, 393 size_t elem_len) 394{ 395 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL) 396 return 0; 397 return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len); 398} 399 400 401int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len) 402{ 403 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL) 404 return 0; 405 return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len); 406} 407 408 409int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len) 410{ 411 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL) 412 return 0; 413 return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len); 414} 415 416 417int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type, 418 const char *ifname, const u8 *addr, void *bss_ctx, 419 void **drv_priv, char *force_ifname, u8 *if_addr, 420 const char *bridge, int use_existing) 421{ 422 if (hapd->driver == NULL || hapd->driver->if_add == NULL) 423 return -1; 424 return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr, 425 bss_ctx, drv_priv, force_ifname, if_addr, 426 bridge, use_existing); 427} 428 429 430int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type, 431 const char *ifname) 432{ 433 if (hapd->driver == NULL || hapd->drv_priv == NULL || 434 hapd->driver->if_remove == NULL) 435 return -1; 436 return hapd->driver->if_remove(hapd->drv_priv, type, ifname); 437} 438 439 440int hostapd_set_ieee8021x(struct hostapd_data *hapd, 441 struct wpa_bss_params *params) 442{ 443 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL) 444 return 0; 445 return hapd->driver->set_ieee8021x(hapd->drv_priv, params); 446} 447 448 449int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd, 450 const u8 *addr, int idx, u8 *seq) 451{ 452 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL) 453 return 0; 454 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx, 455 seq); 456} 457 458 459int hostapd_flush(struct hostapd_data *hapd) 460{ 461 if (hapd->driver == NULL || hapd->driver->flush == NULL) 462 return 0; 463 return hapd->driver->flush(hapd->drv_priv); 464} 465 466 467static int hostapd_set_freq_params(struct hostapd_freq_params *data, int mode, 468 int freq, int channel, int ht_enabled, 469 int vht_enabled, int sec_channel_offset, 470 int vht_oper_chwidth, int center_segment0, 471 int center_segment1, u32 vht_caps) 472{ 473 int tmp; 474 475 os_memset(data, 0, sizeof(*data)); 476 data->mode = mode; 477 data->freq = freq; 478 data->channel = channel; 479 data->ht_enabled = ht_enabled; 480 data->vht_enabled = vht_enabled; 481 data->sec_channel_offset = sec_channel_offset; 482 data->center_freq1 = freq + sec_channel_offset * 10; 483 data->center_freq2 = 0; 484 data->bandwidth = sec_channel_offset ? 40 : 20; 485 486 /* 487 * This validation code is probably misplaced, maybe it should be 488 * in src/ap/hw_features.c and check the hardware support as well. 489 */ 490 if (data->vht_enabled) switch (vht_oper_chwidth) { 491 case VHT_CHANWIDTH_USE_HT: 492 if (center_segment1) 493 return -1; 494 if (5000 + center_segment0 * 5 != data->center_freq1 && 495 2407 + center_segment0 * 5 != data->center_freq1) 496 return -1; 497 break; 498 case VHT_CHANWIDTH_80P80MHZ: 499 if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) { 500 wpa_printf(MSG_ERROR, 501 "80+80 channel width is not supported!"); 502 return -1; 503 } 504 if (center_segment1 == center_segment0 + 4 || 505 center_segment1 == center_segment0 - 4) 506 return -1; 507 data->center_freq2 = 5000 + center_segment1 * 5; 508 /* fall through */ 509 case VHT_CHANWIDTH_80MHZ: 510 data->bandwidth = 80; 511 if (vht_oper_chwidth == 1 && center_segment1) 512 return -1; 513 if (vht_oper_chwidth == 3 && !center_segment1) 514 return -1; 515 if (!sec_channel_offset) 516 return -1; 517 /* primary 40 part must match the HT configuration */ 518 tmp = (30 + freq - 5000 - center_segment0 * 5)/20; 519 tmp /= 2; 520 if (data->center_freq1 != 5000 + 521 center_segment0 * 5 - 20 + 40 * tmp) 522 return -1; 523 data->center_freq1 = 5000 + center_segment0 * 5; 524 break; 525 case VHT_CHANWIDTH_160MHZ: 526 data->bandwidth = 160; 527 if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | 528 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) { 529 wpa_printf(MSG_ERROR, 530 "160MHZ channel width is not supported!"); 531 return -1; 532 } 533 if (center_segment1) 534 return -1; 535 if (!sec_channel_offset) 536 return -1; 537 /* primary 40 part must match the HT configuration */ 538 tmp = (70 + freq - 5000 - center_segment0 * 5)/20; 539 tmp /= 2; 540 if (data->center_freq1 != 5000 + 541 center_segment0 * 5 - 60 + 40 * tmp) 542 return -1; 543 data->center_freq1 = 5000 + center_segment0 * 5; 544 break; 545 } 546 547 return 0; 548} 549 550 551int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, 552 int channel, int ht_enabled, int vht_enabled, 553 int sec_channel_offset, int vht_oper_chwidth, 554 int center_segment0, int center_segment1) 555{ 556 struct hostapd_freq_params data; 557 558 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled, 559 vht_enabled, sec_channel_offset, 560 vht_oper_chwidth, 561 center_segment0, center_segment1, 562 hapd->iface->current_mode->vht_capab)) 563 return -1; 564 565 if (hapd->driver == NULL) 566 return 0; 567 if (hapd->driver->set_freq == NULL) 568 return 0; 569 return hapd->driver->set_freq(hapd->drv_priv, &data); 570} 571 572int hostapd_set_rts(struct hostapd_data *hapd, int rts) 573{ 574 if (hapd->driver == NULL || hapd->driver->set_rts == NULL) 575 return 0; 576 return hapd->driver->set_rts(hapd->drv_priv, rts); 577} 578 579 580int hostapd_set_frag(struct hostapd_data *hapd, int frag) 581{ 582 if (hapd->driver == NULL || hapd->driver->set_frag == NULL) 583 return 0; 584 return hapd->driver->set_frag(hapd->drv_priv, frag); 585} 586 587 588int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr, 589 int total_flags, int flags_or, int flags_and) 590{ 591 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL) 592 return 0; 593 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags, 594 flags_or, flags_and); 595} 596 597 598int hostapd_set_country(struct hostapd_data *hapd, const char *country) 599{ 600 if (hapd->driver == NULL || 601 hapd->driver->set_country == NULL) 602 return 0; 603 return hapd->driver->set_country(hapd->drv_priv, country); 604} 605 606 607int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs, 608 int cw_min, int cw_max, int burst_time) 609{ 610 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL) 611 return 0; 612 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs, 613 cw_min, cw_max, burst_time); 614} 615 616 617struct hostapd_hw_modes * 618hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes, 619 u16 *flags) 620{ 621 if (hapd->driver == NULL || 622 hapd->driver->get_hw_feature_data == NULL) 623 return NULL; 624 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes, 625 flags); 626} 627 628 629int hostapd_driver_commit(struct hostapd_data *hapd) 630{ 631 if (hapd->driver == NULL || hapd->driver->commit == NULL) 632 return 0; 633 return hapd->driver->commit(hapd->drv_priv); 634} 635 636 637int hostapd_drv_none(struct hostapd_data *hapd) 638{ 639 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0; 640} 641 642 643int hostapd_driver_scan(struct hostapd_data *hapd, 644 struct wpa_driver_scan_params *params) 645{ 646 if (hapd->driver && hapd->driver->scan2) 647 return hapd->driver->scan2(hapd->drv_priv, params); 648 return -1; 649} 650 651 652struct wpa_scan_results * hostapd_driver_get_scan_results( 653 struct hostapd_data *hapd) 654{ 655 if (hapd->driver && hapd->driver->get_scan_results2) 656 return hapd->driver->get_scan_results2(hapd->drv_priv); 657 return NULL; 658} 659 660 661int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start, 662 int duration) 663{ 664 if (hapd->driver && hapd->driver->set_noa) 665 return hapd->driver->set_noa(hapd->drv_priv, count, start, 666 duration); 667 return -1; 668} 669 670 671int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd, 672 enum wpa_alg alg, const u8 *addr, 673 int key_idx, int set_tx, 674 const u8 *seq, size_t seq_len, 675 const u8 *key, size_t key_len) 676{ 677 if (hapd->driver == NULL || hapd->driver->set_key == NULL) 678 return 0; 679 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr, 680 key_idx, set_tx, seq, seq_len, key, 681 key_len); 682} 683 684 685int hostapd_drv_send_mlme(struct hostapd_data *hapd, 686 const void *msg, size_t len, int noack) 687{ 688 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL) 689 return 0; 690 return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack); 691} 692 693 694int hostapd_drv_sta_deauth(struct hostapd_data *hapd, 695 const u8 *addr, int reason) 696{ 697 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL) 698 return 0; 699 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr, 700 reason); 701} 702 703 704int hostapd_drv_sta_disassoc(struct hostapd_data *hapd, 705 const u8 *addr, int reason) 706{ 707 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL) 708 return 0; 709 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr, 710 reason); 711} 712 713 714int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper, 715 const u8 *peer, u8 *buf, u16 *buf_len) 716{ 717 if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL) 718 return 0; 719 return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf, 720 buf_len); 721} 722 723 724int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq, 725 unsigned int wait, const u8 *dst, const u8 *data, 726 size_t len) 727{ 728 if (hapd->driver == NULL || hapd->driver->send_action == NULL) 729 return 0; 730 return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst, 731 hapd->own_addr, hapd->own_addr, data, 732 len, 0); 733} 734 735 736int hostapd_start_dfs_cac(struct hostapd_iface *iface, int mode, int freq, 737 int channel, int ht_enabled, int vht_enabled, 738 int sec_channel_offset, int vht_oper_chwidth, 739 int center_segment0, int center_segment1) 740{ 741 struct hostapd_data *hapd = iface->bss[0]; 742 struct hostapd_freq_params data; 743 int res; 744 745 if (!hapd->driver || !hapd->driver->start_dfs_cac) 746 return 0; 747 748 if (!iface->conf->ieee80211h) { 749 wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality " 750 "is not enabled"); 751 return -1; 752 } 753 754 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled, 755 vht_enabled, sec_channel_offset, 756 vht_oper_chwidth, center_segment0, 757 center_segment1, 758 iface->current_mode->vht_capab)) 759 return -1; 760 761 res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data); 762 if (!res) 763 iface->cac_started = 1; 764 765 return res; 766} 767 768 769int hostapd_drv_set_qos_map(struct hostapd_data *hapd, 770 const u8 *qos_map_set, u8 qos_map_set_len) 771{ 772 if (hapd->driver == NULL || hapd->driver->set_qos_map == NULL) 773 return 0; 774 return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set, 775 qos_map_set_len); 776} 777