ap_drv_ops.c revision 68d0e3ed07847339aedfac8e02f50db68c702e52
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); 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) 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); 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->driver->if_remove == NULL) 434 return -1; 435 return hapd->driver->if_remove(hapd->drv_priv, type, ifname); 436} 437 438 439int hostapd_set_ieee8021x(struct hostapd_data *hapd, 440 struct wpa_bss_params *params) 441{ 442 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL) 443 return 0; 444 return hapd->driver->set_ieee8021x(hapd->drv_priv, params); 445} 446 447 448int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd, 449 const u8 *addr, int idx, u8 *seq) 450{ 451 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL) 452 return 0; 453 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx, 454 seq); 455} 456 457 458int hostapd_flush(struct hostapd_data *hapd) 459{ 460 if (hapd->driver == NULL || hapd->driver->flush == NULL) 461 return 0; 462 return hapd->driver->flush(hapd->drv_priv); 463} 464 465 466static int hostapd_set_freq_params(struct hostapd_freq_params *data, int mode, 467 int freq, int channel, int ht_enabled, 468 int vht_enabled, int sec_channel_offset, 469 int vht_oper_chwidth, int center_segment0, 470 int center_segment1, u32 vht_caps) 471{ 472 int tmp; 473 474 os_memset(data, 0, sizeof(*data)); 475 data->mode = mode; 476 data->freq = freq; 477 data->channel = channel; 478 data->ht_enabled = ht_enabled; 479 data->vht_enabled = vht_enabled; 480 data->sec_channel_offset = sec_channel_offset; 481 data->center_freq1 = freq + sec_channel_offset * 10; 482 data->center_freq2 = 0; 483 data->bandwidth = sec_channel_offset ? 40 : 20; 484 485 /* 486 * This validation code is probably misplaced, maybe it should be 487 * in src/ap/hw_features.c and check the hardware support as well. 488 */ 489 if (data->vht_enabled) switch (vht_oper_chwidth) { 490 case VHT_CHANWIDTH_USE_HT: 491 if (center_segment1) 492 return -1; 493 if (5000 + center_segment0 * 5 != data->center_freq1) 494 return -1; 495 break; 496 case VHT_CHANWIDTH_80P80MHZ: 497 if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) { 498 wpa_printf(MSG_ERROR, 499 "80+80 channel width is not supported!"); 500 return -1; 501 } 502 if (center_segment1 == center_segment0 + 4 || 503 center_segment1 == center_segment0 - 4) 504 return -1; 505 data->center_freq2 = 5000 + center_segment1 * 5; 506 /* fall through */ 507 case VHT_CHANWIDTH_80MHZ: 508 data->bandwidth = 80; 509 if (vht_oper_chwidth == 1 && center_segment1) 510 return -1; 511 if (vht_oper_chwidth == 3 && !center_segment1) 512 return -1; 513 if (!sec_channel_offset) 514 return -1; 515 /* primary 40 part must match the HT configuration */ 516 tmp = (30 + freq - 5000 - center_segment0 * 5)/20; 517 tmp /= 2; 518 if (data->center_freq1 != 5000 + 519 center_segment0 * 5 - 20 + 40 * tmp) 520 return -1; 521 data->center_freq1 = 5000 + center_segment0 * 5; 522 break; 523 case VHT_CHANWIDTH_160MHZ: 524 data->bandwidth = 160; 525 if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | 526 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) { 527 wpa_printf(MSG_ERROR, 528 "160MHZ channel width is not supported!"); 529 return -1; 530 } 531 if (center_segment1) 532 return -1; 533 if (!sec_channel_offset) 534 return -1; 535 /* primary 40 part must match the HT configuration */ 536 tmp = (70 + freq - 5000 - center_segment0 * 5)/20; 537 tmp /= 2; 538 if (data->center_freq1 != 5000 + 539 center_segment0 * 5 - 60 + 40 * tmp) 540 return -1; 541 data->center_freq1 = 5000 + center_segment0 * 5; 542 break; 543 } 544 545 return 0; 546} 547 548 549int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, 550 int channel, int ht_enabled, int vht_enabled, 551 int sec_channel_offset, int vht_oper_chwidth, 552 int center_segment0, int center_segment1) 553{ 554 struct hostapd_freq_params data; 555 556 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled, 557 vht_enabled, sec_channel_offset, 558 vht_oper_chwidth, 559 center_segment0, center_segment1, 560 hapd->iface->current_mode->vht_capab)) 561 return -1; 562 563 if (hapd->driver == NULL) 564 return 0; 565 if (hapd->driver->set_freq == NULL) 566 return 0; 567 return hapd->driver->set_freq(hapd->drv_priv, &data); 568} 569 570int hostapd_set_rts(struct hostapd_data *hapd, int rts) 571{ 572 if (hapd->driver == NULL || hapd->driver->set_rts == NULL) 573 return 0; 574 return hapd->driver->set_rts(hapd->drv_priv, rts); 575} 576 577 578int hostapd_set_frag(struct hostapd_data *hapd, int frag) 579{ 580 if (hapd->driver == NULL || hapd->driver->set_frag == NULL) 581 return 0; 582 return hapd->driver->set_frag(hapd->drv_priv, frag); 583} 584 585 586int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr, 587 int total_flags, int flags_or, int flags_and) 588{ 589 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL) 590 return 0; 591 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags, 592 flags_or, flags_and); 593} 594 595 596int hostapd_set_country(struct hostapd_data *hapd, const char *country) 597{ 598 if (hapd->driver == NULL || 599 hapd->driver->set_country == NULL) 600 return 0; 601 return hapd->driver->set_country(hapd->drv_priv, country); 602} 603 604 605int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs, 606 int cw_min, int cw_max, int burst_time) 607{ 608 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL) 609 return 0; 610 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs, 611 cw_min, cw_max, burst_time); 612} 613 614 615struct hostapd_hw_modes * 616hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes, 617 u16 *flags) 618{ 619 if (hapd->driver == NULL || 620 hapd->driver->get_hw_feature_data == NULL) 621 return NULL; 622 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes, 623 flags); 624} 625 626 627int hostapd_driver_commit(struct hostapd_data *hapd) 628{ 629 if (hapd->driver == NULL || hapd->driver->commit == NULL) 630 return 0; 631 return hapd->driver->commit(hapd->drv_priv); 632} 633 634 635int hostapd_drv_none(struct hostapd_data *hapd) 636{ 637 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0; 638} 639 640 641int hostapd_driver_scan(struct hostapd_data *hapd, 642 struct wpa_driver_scan_params *params) 643{ 644 if (hapd->driver && hapd->driver->scan2) 645 return hapd->driver->scan2(hapd->drv_priv, params); 646 return -1; 647} 648 649 650struct wpa_scan_results * hostapd_driver_get_scan_results( 651 struct hostapd_data *hapd) 652{ 653 if (hapd->driver && hapd->driver->get_scan_results2) 654 return hapd->driver->get_scan_results2(hapd->drv_priv); 655 return NULL; 656} 657 658 659int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start, 660 int duration) 661{ 662 if (hapd->driver && hapd->driver->set_noa) 663 return hapd->driver->set_noa(hapd->drv_priv, count, start, 664 duration); 665 return -1; 666} 667 668 669int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd, 670 enum wpa_alg alg, const u8 *addr, 671 int key_idx, int set_tx, 672 const u8 *seq, size_t seq_len, 673 const u8 *key, size_t key_len) 674{ 675 if (hapd->driver == NULL || hapd->driver->set_key == NULL) 676 return 0; 677 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr, 678 key_idx, set_tx, seq, seq_len, key, 679 key_len); 680} 681 682 683int hostapd_drv_send_mlme(struct hostapd_data *hapd, 684 const void *msg, size_t len, int noack) 685{ 686 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL) 687 return 0; 688 return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack); 689} 690 691 692int hostapd_drv_sta_deauth(struct hostapd_data *hapd, 693 const u8 *addr, int reason) 694{ 695 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL) 696 return 0; 697 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr, 698 reason); 699} 700 701 702int hostapd_drv_sta_disassoc(struct hostapd_data *hapd, 703 const u8 *addr, int reason) 704{ 705 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL) 706 return 0; 707 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr, 708 reason); 709} 710 711 712int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper, 713 const u8 *peer, u8 *buf, u16 *buf_len) 714{ 715 if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL) 716 return 0; 717 return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf, 718 buf_len); 719} 720 721 722int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq, 723 unsigned int wait, const u8 *dst, const u8 *data, 724 size_t len) 725{ 726 if (hapd->driver == NULL || hapd->driver->send_action == NULL) 727 return 0; 728 return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst, 729 hapd->own_addr, hapd->own_addr, data, 730 len, 0); 731} 732 733int hostapd_start_dfs_cac(struct hostapd_data *hapd, int mode, int freq, 734 int channel, int ht_enabled, int vht_enabled, 735 int sec_channel_offset, int vht_oper_chwidth, 736 int center_segment0, int center_segment1) 737{ 738 struct hostapd_freq_params data; 739 int res; 740 741 if (!hapd->driver || !hapd->driver->start_dfs_cac) 742 return 0; 743 744 if (!hapd->iface->conf->ieee80211h) { 745 wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality " 746 "is not enabled"); 747 return -1; 748 } 749 750 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled, 751 vht_enabled, sec_channel_offset, 752 vht_oper_chwidth, center_segment0, 753 center_segment1, 754 hapd->iface->current_mode->vht_capab)) 755 return -1; 756 757 res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data); 758 if (!res) 759 hapd->cac_started = 1; 760 761 return res; 762} 763 764 765int hostapd_drv_set_qos_map(struct hostapd_data *hapd, 766 const u8 *qos_map_set, u8 qos_map_set_len) 767{ 768 if (hapd->driver == NULL || hapd->driver->set_qos_map == NULL) 769 return 0; 770 return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set, 771 qos_map_set_len); 772} 773