1 /* 2 * hostapd / Hardware feature query and different modes 3 * Copyright 2002-2003, Instant802 Networks, Inc. 4 * Copyright 2005-2006, Devicescape Software, Inc. 5 * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * Alternatively, this software may be distributed under the terms of BSD 12 * license. 13 * 14 * See README and COPYING for more details. 15 */ 16 17 #include "utils/includes.h" 18 19 #include "utils/common.h" 20 #include "utils/eloop.h" 21 #include "common/ieee802_11_defs.h" 22 #include "common/ieee802_11_common.h" 23 #include "drivers/driver.h" 24 #include "hostapd.h" 25 #include "ap_config.h" 26 #include "ap_drv_ops.h" 27 #include "hw_features.h" 28 29 30 void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features, 31 size_t num_hw_features) 32 { 33 size_t i; 34 35 if (hw_features == NULL) 36 return; 37 38 for (i = 0; i < num_hw_features; i++) { 39 os_free(hw_features[i].channels); 40 os_free(hw_features[i].rates); 41 } 42 43 os_free(hw_features); 44 } 45 46 47 int hostapd_get_hw_features(struct hostapd_iface *iface) 48 { 49 struct hostapd_data *hapd = iface->bss[0]; 50 int ret = 0, i, j; 51 u16 num_modes, flags; 52 struct hostapd_hw_modes *modes; 53 54 if (hostapd_drv_none(hapd)) 55 return -1; 56 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags); 57 if (modes == NULL) { 58 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 59 HOSTAPD_LEVEL_DEBUG, 60 "Fetching hardware channel/rate support not " 61 "supported."); 62 return -1; 63 } 64 65 iface->hw_flags = flags; 66 67 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); 68 iface->hw_features = modes; 69 iface->num_hw_features = num_modes; 70 71 for (i = 0; i < num_modes; i++) { 72 struct hostapd_hw_modes *feature = &modes[i]; 73 /* set flag for channels we can use in current regulatory 74 * domain */ 75 for (j = 0; j < feature->num_channels; j++) { 76 /* 77 * Disable all channels that are marked not to allow 78 * IBSS operation or active scanning. In addition, 79 * disable all channels that require radar detection, 80 * since that (in addition to full DFS) is not yet 81 * supported. 82 */ 83 if (feature->channels[j].flag & 84 (HOSTAPD_CHAN_NO_IBSS | 85 HOSTAPD_CHAN_PASSIVE_SCAN | 86 HOSTAPD_CHAN_RADAR)) 87 feature->channels[j].flag |= 88 HOSTAPD_CHAN_DISABLED; 89 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED) 90 continue; 91 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d " 92 "chan=%d freq=%d MHz max_tx_power=%d dBm", 93 feature->mode, 94 feature->channels[j].chan, 95 feature->channels[j].freq, 96 feature->channels[j].max_tx_power); 97 } 98 } 99 100 return ret; 101 } 102 103 104 int hostapd_prepare_rates(struct hostapd_data *hapd, 105 struct hostapd_hw_modes *mode) 106 { 107 int i, num_basic_rates = 0; 108 int basic_rates_a[] = { 60, 120, 240, -1 }; 109 int basic_rates_b[] = { 10, 20, -1 }; 110 int basic_rates_g[] = { 10, 20, 55, 110, -1 }; 111 int *basic_rates; 112 113 if (hapd->iconf->basic_rates) 114 basic_rates = hapd->iconf->basic_rates; 115 else switch (mode->mode) { 116 case HOSTAPD_MODE_IEEE80211A: 117 basic_rates = basic_rates_a; 118 break; 119 case HOSTAPD_MODE_IEEE80211B: 120 basic_rates = basic_rates_b; 121 break; 122 case HOSTAPD_MODE_IEEE80211G: 123 basic_rates = basic_rates_g; 124 break; 125 default: 126 return -1; 127 } 128 129 if (hostapd_set_rate_sets(hapd, hapd->iconf->supported_rates, 130 basic_rates, mode->mode)) { 131 wpa_printf(MSG_ERROR, "Failed to update rate sets in kernel " 132 "module"); 133 } 134 135 os_free(hapd->iface->current_rates); 136 hapd->iface->num_rates = 0; 137 138 hapd->iface->current_rates = 139 os_zalloc(mode->num_rates * sizeof(struct hostapd_rate_data)); 140 if (!hapd->iface->current_rates) { 141 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate " 142 "table."); 143 return -1; 144 } 145 146 for (i = 0; i < mode->num_rates; i++) { 147 struct hostapd_rate_data *rate; 148 149 if (hapd->iconf->supported_rates && 150 !hostapd_rate_found(hapd->iconf->supported_rates, 151 mode->rates[i])) 152 continue; 153 154 rate = &hapd->iface->current_rates[hapd->iface->num_rates]; 155 rate->rate = mode->rates[i]; 156 if (hostapd_rate_found(basic_rates, rate->rate)) { 157 rate->flags |= HOSTAPD_RATE_BASIC; 158 num_basic_rates++; 159 } 160 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x", 161 hapd->iface->num_rates, rate->rate, rate->flags); 162 hapd->iface->num_rates++; 163 } 164 165 if ((hapd->iface->num_rates == 0 || num_basic_rates == 0) && 166 (!hapd->iconf->ieee80211n || !hapd->iconf->require_ht)) { 167 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic " 168 "rate sets (%d,%d).", 169 hapd->iface->num_rates, num_basic_rates); 170 return -1; 171 } 172 173 return 0; 174 } 175 176 177 #ifdef CONFIG_IEEE80211N 178 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface) 179 { 180 int sec_chan, ok, j, first; 181 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, 182 184, 192 }; 183 size_t k; 184 185 if (!iface->conf->secondary_channel) 186 return 1; /* HT40 not used */ 187 188 sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4; 189 wpa_printf(MSG_DEBUG, "HT40: control channel: %d " 190 "secondary channel: %d", 191 iface->conf->channel, sec_chan); 192 193 /* Verify that HT40 secondary channel is an allowed 20 MHz 194 * channel */ 195 ok = 0; 196 for (j = 0; j < iface->current_mode->num_channels; j++) { 197 struct hostapd_channel_data *chan = 198 &iface->current_mode->channels[j]; 199 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) && 200 chan->chan == sec_chan) { 201 ok = 1; 202 break; 203 } 204 } 205 if (!ok) { 206 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed", 207 sec_chan); 208 return 0; 209 } 210 211 /* 212 * Verify that HT40 primary,secondary channel pair is allowed per 213 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since 214 * 2.4 GHz rules allow all cases where the secondary channel fits into 215 * the list of allowed channels (already checked above). 216 */ 217 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A) 218 return 1; 219 220 if (iface->conf->secondary_channel > 0) 221 first = iface->conf->channel; 222 else 223 first = sec_chan; 224 225 ok = 0; 226 for (k = 0; k < sizeof(allowed) / sizeof(allowed[0]); k++) { 227 if (first == allowed[k]) { 228 ok = 1; 229 break; 230 } 231 } 232 if (!ok) { 233 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed", 234 iface->conf->channel, 235 iface->conf->secondary_channel); 236 return 0; 237 } 238 239 return 1; 240 } 241 242 243 static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface) 244 { 245 if (iface->conf->secondary_channel > 0) { 246 iface->conf->channel += 4; 247 iface->conf->secondary_channel = -1; 248 } else { 249 iface->conf->channel -= 4; 250 iface->conf->secondary_channel = 1; 251 } 252 } 253 254 255 static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss, 256 int *pri_chan, int *sec_chan) 257 { 258 struct ieee80211_ht_operation *oper; 259 struct ieee802_11_elems elems; 260 261 *pri_chan = *sec_chan = 0; 262 263 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0); 264 if (elems.ht_operation && 265 elems.ht_operation_len >= sizeof(*oper)) { 266 oper = (struct ieee80211_ht_operation *) elems.ht_operation; 267 *pri_chan = oper->control_chan; 268 if (oper->ht_param & HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH) { 269 int sec = oper->ht_param & 270 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; 271 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) 272 *sec_chan = *pri_chan + 4; 273 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) 274 *sec_chan = *pri_chan - 4; 275 } 276 } 277 } 278 279 280 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface, 281 struct wpa_scan_results *scan_res) 282 { 283 int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss; 284 int bss_pri_chan, bss_sec_chan; 285 size_t i; 286 int match; 287 288 pri_chan = iface->conf->channel; 289 sec_chan = iface->conf->secondary_channel * 4; 290 pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan); 291 if (iface->conf->secondary_channel > 0) 292 sec_freq = pri_freq + 20; 293 else 294 sec_freq = pri_freq - 20; 295 296 /* 297 * Switch PRI/SEC channels if Beacons were detected on selected SEC 298 * channel, but not on selected PRI channel. 299 */ 300 pri_bss = sec_bss = 0; 301 for (i = 0; i < scan_res->num; i++) { 302 struct wpa_scan_res *bss = scan_res->res[i]; 303 if (bss->freq == pri_freq) 304 pri_bss++; 305 else if (bss->freq == sec_freq) 306 sec_bss++; 307 } 308 if (sec_bss && !pri_bss) { 309 wpa_printf(MSG_INFO, "Switch own primary and secondary " 310 "channel to get secondary channel with no Beacons " 311 "from other BSSes"); 312 ieee80211n_switch_pri_sec(iface); 313 } 314 315 /* 316 * Match PRI/SEC channel with any existing HT40 BSS on the same 317 * channels that we are about to use (if already mixed order in 318 * existing BSSes, use own preference). 319 */ 320 match = 0; 321 for (i = 0; i < scan_res->num; i++) { 322 struct wpa_scan_res *bss = scan_res->res[i]; 323 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan); 324 if (pri_chan == bss_pri_chan && 325 sec_chan == bss_sec_chan) { 326 match = 1; 327 break; 328 } 329 } 330 if (!match) { 331 for (i = 0; i < scan_res->num; i++) { 332 struct wpa_scan_res *bss = scan_res->res[i]; 333 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, 334 &bss_sec_chan); 335 if (pri_chan == bss_sec_chan && 336 sec_chan == bss_pri_chan) { 337 wpa_printf(MSG_INFO, "Switch own primary and " 338 "secondary channel due to BSS " 339 "overlap with " MACSTR, 340 MAC2STR(bss->bssid)); 341 ieee80211n_switch_pri_sec(iface); 342 break; 343 } 344 } 345 } 346 347 return 1; 348 } 349 350 351 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface, 352 struct wpa_scan_results *scan_res) 353 { 354 int pri_freq, sec_freq; 355 int affected_start, affected_end; 356 size_t i; 357 358 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); 359 if (iface->conf->secondary_channel > 0) 360 sec_freq = pri_freq + 20; 361 else 362 sec_freq = pri_freq - 20; 363 affected_start = (pri_freq + sec_freq) / 2 - 25; 364 affected_end = (pri_freq + sec_freq) / 2 + 25; 365 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", 366 affected_start, affected_end); 367 for (i = 0; i < scan_res->num; i++) { 368 struct wpa_scan_res *bss = scan_res->res[i]; 369 int pri = bss->freq; 370 int sec = pri; 371 int sec_chan, pri_chan; 372 373 ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan); 374 375 if (sec_chan) { 376 if (sec_chan < pri_chan) 377 sec = pri - 20; 378 else 379 sec = pri + 20; 380 } 381 382 if ((pri < affected_start || pri > affected_end) && 383 (sec < affected_start || sec > affected_end)) 384 continue; /* not within affected channel range */ 385 386 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR 387 " freq=%d pri=%d sec=%d", 388 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan); 389 390 if (sec_chan) { 391 if (pri_freq != pri || sec_freq != sec) { 392 wpa_printf(MSG_DEBUG, "40 MHz pri/sec " 393 "mismatch with BSS " MACSTR 394 " <%d,%d> (chan=%d%c) vs. <%d,%d>", 395 MAC2STR(bss->bssid), 396 pri, sec, pri_chan, 397 sec > pri ? '+' : '-', 398 pri_freq, sec_freq); 399 return 0; 400 } 401 } 402 403 /* TODO: 40 MHz intolerant */ 404 } 405 406 return 1; 407 } 408 409 410 static void ieee80211n_check_scan(struct hostapd_iface *iface) 411 { 412 struct wpa_scan_results *scan_res; 413 int oper40; 414 int res; 415 416 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is 417 * allowed per IEEE 802.11n/D7.0, 11.14.3.2 */ 418 419 iface->scan_cb = NULL; 420 421 scan_res = hostapd_driver_get_scan_results(iface->bss[0]); 422 if (scan_res == NULL) { 423 hostapd_setup_interface_complete(iface, 1); 424 return; 425 } 426 427 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A) 428 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res); 429 else 430 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res); 431 wpa_scan_results_free(scan_res); 432 433 if (!oper40) { 434 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on " 435 "channel pri=%d sec=%d based on overlapping BSSes", 436 iface->conf->channel, 437 iface->conf->channel + 438 iface->conf->secondary_channel * 4); 439 iface->conf->secondary_channel = 0; 440 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; 441 } 442 443 res = ieee80211n_allowed_ht40_channel_pair(iface); 444 hostapd_setup_interface_complete(iface, !res); 445 } 446 447 448 static int ieee80211n_check_40mhz(struct hostapd_iface *iface) 449 { 450 struct wpa_driver_scan_params params; 451 452 if (!iface->conf->secondary_channel) 453 return 0; /* HT40 not used */ 454 455 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling " 456 "40 MHz channel"); 457 os_memset(¶ms, 0, sizeof(params)); 458 /* TODO: scan only the needed frequency */ 459 if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) { 460 wpa_printf(MSG_ERROR, "Failed to request a scan of " 461 "neighboring BSSes"); 462 return -1; 463 } 464 465 iface->scan_cb = ieee80211n_check_scan; 466 return 1; 467 } 468 469 470 static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface) 471 { 472 u16 hw = iface->current_mode->ht_capab; 473 u16 conf = iface->conf->ht_capab; 474 475 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) && 476 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) { 477 wpa_printf(MSG_ERROR, "Driver does not support configured " 478 "HT capability [LDPC]"); 479 return 0; 480 } 481 482 if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) && 483 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { 484 wpa_printf(MSG_ERROR, "Driver does not support configured " 485 "HT capability [HT40*]"); 486 return 0; 487 } 488 489 if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) && 490 (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) { 491 wpa_printf(MSG_ERROR, "Driver does not support configured " 492 "HT capability [SMPS-*]"); 493 return 0; 494 } 495 496 if ((conf & HT_CAP_INFO_GREEN_FIELD) && 497 !(hw & HT_CAP_INFO_GREEN_FIELD)) { 498 wpa_printf(MSG_ERROR, "Driver does not support configured " 499 "HT capability [GF]"); 500 return 0; 501 } 502 503 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) && 504 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) { 505 wpa_printf(MSG_ERROR, "Driver does not support configured " 506 "HT capability [SHORT-GI-20]"); 507 return 0; 508 } 509 510 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) && 511 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) { 512 wpa_printf(MSG_ERROR, "Driver does not support configured " 513 "HT capability [SHORT-GI-40]"); 514 return 0; 515 } 516 517 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) { 518 wpa_printf(MSG_ERROR, "Driver does not support configured " 519 "HT capability [TX-STBC]"); 520 return 0; 521 } 522 523 if ((conf & HT_CAP_INFO_RX_STBC_MASK) > 524 (hw & HT_CAP_INFO_RX_STBC_MASK)) { 525 wpa_printf(MSG_ERROR, "Driver does not support configured " 526 "HT capability [RX-STBC*]"); 527 return 0; 528 } 529 530 if ((conf & HT_CAP_INFO_DELAYED_BA) && 531 !(hw & HT_CAP_INFO_DELAYED_BA)) { 532 wpa_printf(MSG_ERROR, "Driver does not support configured " 533 "HT capability [DELAYED-BA]"); 534 return 0; 535 } 536 537 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) && 538 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) { 539 wpa_printf(MSG_ERROR, "Driver does not support configured " 540 "HT capability [MAX-AMSDU-7935]"); 541 return 0; 542 } 543 544 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) && 545 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) { 546 wpa_printf(MSG_ERROR, "Driver does not support configured " 547 "HT capability [DSSS_CCK-40]"); 548 return 0; 549 } 550 551 if ((conf & HT_CAP_INFO_PSMP_SUPP) && !(hw & HT_CAP_INFO_PSMP_SUPP)) { 552 wpa_printf(MSG_ERROR, "Driver does not support configured " 553 "HT capability [PSMP]"); 554 return 0; 555 } 556 557 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) && 558 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) { 559 wpa_printf(MSG_ERROR, "Driver does not support configured " 560 "HT capability [LSIG-TXOP-PROT]"); 561 return 0; 562 } 563 564 return 1; 565 } 566 567 #endif /* CONFIG_IEEE80211N */ 568 569 570 int hostapd_check_ht_capab(struct hostapd_iface *iface) 571 { 572 #ifdef CONFIG_IEEE80211N 573 int ret; 574 if (!iface->conf->ieee80211n) 575 return 0; 576 if (!ieee80211n_supported_ht_capab(iface)) 577 return -1; 578 ret = ieee80211n_check_40mhz(iface); 579 if (ret) 580 return ret; 581 if (!ieee80211n_allowed_ht40_channel_pair(iface)) 582 return -1; 583 #endif /* CONFIG_IEEE80211N */ 584 585 return 0; 586 } 587 588 589 /** 590 * hostapd_select_hw_mode - Select the hardware mode 591 * @iface: Pointer to interface data. 592 * Returns: 0 on success, < 0 on failure 593 * 594 * Sets up the hardware mode, channel, rates, and passive scanning 595 * based on the configuration. 596 */ 597 int hostapd_select_hw_mode(struct hostapd_iface *iface) 598 { 599 int i, j, ok; 600 601 if (iface->num_hw_features < 1) 602 return -1; 603 604 iface->current_mode = NULL; 605 for (i = 0; i < iface->num_hw_features; i++) { 606 struct hostapd_hw_modes *mode = &iface->hw_features[i]; 607 if (mode->mode == iface->conf->hw_mode) { 608 iface->current_mode = mode; 609 break; 610 } 611 } 612 613 if (iface->current_mode == NULL) { 614 wpa_printf(MSG_ERROR, "Hardware does not support configured " 615 "mode"); 616 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, 617 HOSTAPD_LEVEL_WARNING, 618 "Hardware does not support configured mode " 619 "(%d) (hw_mode in hostapd.conf)", 620 (int) iface->conf->hw_mode); 621 return -2; 622 } 623 624 ok = 0; 625 for (j = 0; j < iface->current_mode->num_channels; j++) { 626 struct hostapd_channel_data *chan = 627 &iface->current_mode->channels[j]; 628 if (chan->chan == iface->conf->channel) { 629 if (chan->flag & HOSTAPD_CHAN_DISABLED) { 630 wpa_printf(MSG_ERROR, 631 "channel [%i] (%i) is disabled for " 632 "use in AP mode, flags: 0x%x", 633 j, chan->chan, chan->flag); 634 } else { 635 ok = 1; 636 break; 637 } 638 } 639 } 640 if (ok && iface->conf->secondary_channel) { 641 int sec_ok = 0; 642 int sec_chan = iface->conf->channel + 643 iface->conf->secondary_channel * 4; 644 for (j = 0; j < iface->current_mode->num_channels; j++) { 645 struct hostapd_channel_data *chan = 646 &iface->current_mode->channels[j]; 647 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) && 648 (chan->chan == sec_chan)) { 649 sec_ok = 1; 650 break; 651 } 652 } 653 if (!sec_ok) { 654 hostapd_logger(iface->bss[0], NULL, 655 HOSTAPD_MODULE_IEEE80211, 656 HOSTAPD_LEVEL_WARNING, 657 "Configured HT40 secondary channel " 658 "(%d) not found from the channel list " 659 "of current mode (%d) %s", 660 sec_chan, iface->current_mode->mode, 661 hostapd_hw_mode_txt( 662 iface->current_mode->mode)); 663 ok = 0; 664 } 665 } 666 if (iface->conf->channel == 0) { 667 /* TODO: could request a scan of neighboring BSSes and select 668 * the channel automatically */ 669 wpa_printf(MSG_ERROR, "Channel not configured " 670 "(hw_mode/channel in hostapd.conf)"); 671 return -3; 672 } 673 if (ok == 0 && iface->conf->channel != 0) { 674 hostapd_logger(iface->bss[0], NULL, 675 HOSTAPD_MODULE_IEEE80211, 676 HOSTAPD_LEVEL_WARNING, 677 "Configured channel (%d) not found from the " 678 "channel list of current mode (%d) %s", 679 iface->conf->channel, 680 iface->current_mode->mode, 681 hostapd_hw_mode_txt(iface->current_mode->mode)); 682 iface->current_mode = NULL; 683 } 684 685 if (iface->current_mode == NULL) { 686 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, 687 HOSTAPD_LEVEL_WARNING, 688 "Hardware does not support configured channel"); 689 return -4; 690 } 691 692 return 0; 693 } 694 695 696 const char * hostapd_hw_mode_txt(int mode) 697 { 698 switch (mode) { 699 case HOSTAPD_MODE_IEEE80211A: 700 return "IEEE 802.11a"; 701 case HOSTAPD_MODE_IEEE80211B: 702 return "IEEE 802.11b"; 703 case HOSTAPD_MODE_IEEE80211G: 704 return "IEEE 802.11g"; 705 default: 706 return "UNKNOWN"; 707 } 708 } 709 710 711 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan) 712 { 713 int i; 714 715 if (!hapd->iface->current_mode) 716 return 0; 717 718 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) { 719 struct hostapd_channel_data *ch = 720 &hapd->iface->current_mode->channels[i]; 721 if (ch->chan == chan) 722 return ch->freq; 723 } 724 725 return 0; 726 } 727 728 729 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq) 730 { 731 int i; 732 733 if (!hapd->iface->current_mode) 734 return 0; 735 736 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) { 737 struct hostapd_channel_data *ch = 738 &hapd->iface->current_mode->channels[i]; 739 if (ch->freq == freq) 740 return ch->chan; 741 } 742 743 return 0; 744 } 745