hw_features.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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, 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. #include "includes.h"
  17. #include "hostapd.h"
  18. #include "ieee802_11_defs.h"
  19. #include "hw_features.h"
  20. #include "driver_i.h"
  21. #include "config.h"
  22. void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
  23. size_t num_hw_features)
  24. {
  25. size_t i;
  26. if (hw_features == NULL)
  27. return;
  28. for (i = 0; i < num_hw_features; i++) {
  29. os_free(hw_features[i].channels);
  30. os_free(hw_features[i].rates);
  31. }
  32. os_free(hw_features);
  33. }
  34. int hostapd_get_hw_features(struct hostapd_iface *iface)
  35. {
  36. struct hostapd_data *hapd = iface->bss[0];
  37. int ret = 0, i, j;
  38. u16 num_modes, flags;
  39. struct hostapd_hw_modes *modes;
  40. if (hostapd_drv_none(hapd))
  41. return -1;
  42. modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
  43. if (modes == NULL) {
  44. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  45. HOSTAPD_LEVEL_DEBUG,
  46. "Fetching hardware channel/rate support not "
  47. "supported.");
  48. return -1;
  49. }
  50. iface->hw_flags = flags;
  51. hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
  52. iface->hw_features = modes;
  53. iface->num_hw_features = num_modes;
  54. for (i = 0; i < num_modes; i++) {
  55. struct hostapd_hw_modes *feature = &modes[i];
  56. /* set flag for channels we can use in current regulatory
  57. * domain */
  58. for (j = 0; j < feature->num_channels; j++) {
  59. /*
  60. * Disable all channels that are marked not to allow
  61. * IBSS operation or active scanning. In addition,
  62. * disable all channels that require radar detection,
  63. * since that (in addition to full DFS) is not yet
  64. * supported.
  65. */
  66. if (feature->channels[j].flag &
  67. (HOSTAPD_CHAN_NO_IBSS |
  68. HOSTAPD_CHAN_PASSIVE_SCAN |
  69. HOSTAPD_CHAN_RADAR))
  70. feature->channels[j].flag |=
  71. HOSTAPD_CHAN_DISABLED;
  72. if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
  73. continue;
  74. wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
  75. "chan=%d freq=%d MHz max_tx_power=%d dBm",
  76. feature->mode,
  77. feature->channels[j].chan,
  78. feature->channels[j].freq,
  79. feature->channels[j].max_tx_power);
  80. }
  81. }
  82. return ret;
  83. }
  84. static int hostapd_prepare_rates(struct hostapd_data *hapd,
  85. struct hostapd_hw_modes *mode)
  86. {
  87. int i, num_basic_rates = 0;
  88. int basic_rates_a[] = { 60, 120, 240, -1 };
  89. int basic_rates_b[] = { 10, 20, -1 };
  90. int basic_rates_g[] = { 10, 20, 55, 110, -1 };
  91. int *basic_rates;
  92. if (hapd->iconf->basic_rates)
  93. basic_rates = hapd->iconf->basic_rates;
  94. else switch (mode->mode) {
  95. case HOSTAPD_MODE_IEEE80211A:
  96. basic_rates = basic_rates_a;
  97. break;
  98. case HOSTAPD_MODE_IEEE80211B:
  99. basic_rates = basic_rates_b;
  100. break;
  101. case HOSTAPD_MODE_IEEE80211G:
  102. basic_rates = basic_rates_g;
  103. break;
  104. default:
  105. return -1;
  106. }
  107. if (hostapd_set_rate_sets(hapd, hapd->iconf->supported_rates,
  108. basic_rates, mode->mode)) {
  109. wpa_printf(MSG_ERROR, "Failed to update rate sets in kernel "
  110. "module");
  111. }
  112. os_free(hapd->iface->current_rates);
  113. hapd->iface->num_rates = 0;
  114. hapd->iface->current_rates =
  115. os_malloc(mode->num_rates * sizeof(struct hostapd_rate_data));
  116. if (!hapd->iface->current_rates) {
  117. wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
  118. "table.");
  119. return -1;
  120. }
  121. for (i = 0; i < mode->num_rates; i++) {
  122. struct hostapd_rate_data *rate;
  123. if (hapd->iconf->supported_rates &&
  124. !hostapd_rate_found(hapd->iconf->supported_rates,
  125. mode->rates[i].rate))
  126. continue;
  127. rate = &hapd->iface->current_rates[hapd->iface->num_rates];
  128. os_memcpy(rate, &mode->rates[i],
  129. sizeof(struct hostapd_rate_data));
  130. if (hostapd_rate_found(basic_rates, rate->rate)) {
  131. rate->flags |= HOSTAPD_RATE_BASIC;
  132. num_basic_rates++;
  133. } else
  134. rate->flags &= ~HOSTAPD_RATE_BASIC;
  135. wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
  136. hapd->iface->num_rates, rate->rate, rate->flags);
  137. hapd->iface->num_rates++;
  138. }
  139. if (hapd->iface->num_rates == 0 || num_basic_rates == 0) {
  140. wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
  141. "rate sets (%d,%d).",
  142. hapd->iface->num_rates, num_basic_rates);
  143. return -1;
  144. }
  145. return 0;
  146. }
  147. #ifdef CONFIG_IEEE80211N
  148. static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
  149. {
  150. int sec_chan, ok, j, first;
  151. int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
  152. 184, 192 };
  153. size_t k;
  154. if (!iface->conf->secondary_channel)
  155. return 1; /* HT40 not used */
  156. sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
  157. wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
  158. "secondary channel: %d",
  159. iface->conf->channel, sec_chan);
  160. /* Verify that HT40 secondary channel is an allowed 20 MHz
  161. * channel */
  162. ok = 0;
  163. for (j = 0; j < iface->current_mode->num_channels; j++) {
  164. struct hostapd_channel_data *chan =
  165. &iface->current_mode->channels[j];
  166. if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
  167. chan->chan == sec_chan) {
  168. ok = 1;
  169. break;
  170. }
  171. }
  172. if (!ok) {
  173. wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
  174. sec_chan);
  175. return 0;
  176. }
  177. /*
  178. * Verify that HT40 primary,secondary channel pair is allowed per
  179. * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
  180. * 2.4 GHz rules allow all cases where the secondary channel fits into
  181. * the list of allowed channels (already checked above).
  182. */
  183. if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
  184. return 1;
  185. if (iface->conf->secondary_channel > 0)
  186. first = iface->conf->channel;
  187. else
  188. first = sec_chan;
  189. ok = 0;
  190. for (k = 0; k < sizeof(allowed) / sizeof(allowed[0]); k++) {
  191. if (first == allowed[k]) {
  192. ok = 1;
  193. break;
  194. }
  195. }
  196. if (!ok) {
  197. wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
  198. iface->conf->channel,
  199. iface->conf->secondary_channel);
  200. return 0;
  201. }
  202. return 1;
  203. }
  204. static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
  205. {
  206. if (iface->conf->secondary_channel > 0) {
  207. iface->conf->channel += 4;
  208. iface->conf->secondary_channel = -1;
  209. } else {
  210. iface->conf->channel -= 4;
  211. iface->conf->secondary_channel = 1;
  212. }
  213. }
  214. static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface)
  215. {
  216. int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
  217. const struct hostapd_neighbor_bss *n;
  218. size_t i, num;
  219. int match;
  220. pri_chan = iface->conf->channel;
  221. sec_chan = iface->conf->secondary_channel * 4;
  222. pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
  223. if (iface->conf->secondary_channel > 0)
  224. sec_freq = pri_freq + 20;
  225. else
  226. sec_freq = pri_freq - 20;
  227. n = hostapd_driver_get_neighbor_bss(iface->bss[0], &num);
  228. /*
  229. * Switch PRI/SEC channels if Beacons were detected on selected SEC
  230. * channel, but not on selected PRI channel.
  231. */
  232. pri_bss = sec_bss = 0;
  233. for (i = 0; n && i < num; i++) {
  234. if (n[i].freq == pri_freq)
  235. pri_bss++;
  236. else if (n[i].freq == sec_freq)
  237. sec_bss++;
  238. }
  239. if (sec_bss && !pri_bss) {
  240. wpa_printf(MSG_INFO, "Switch own primary and secondary "
  241. "channel to get secondary channel with no Beacons "
  242. "from other BSSes");
  243. ieee80211n_switch_pri_sec(iface);
  244. }
  245. /*
  246. * Match PRI/SEC channel with any existing HT40 BSS on the same
  247. * channels that we are about to use (if already mixed order in
  248. * existing BSSes, use own preference).
  249. */
  250. match = 0;
  251. for (i = 0; n && i < num; i++) {
  252. if (pri_chan == n[i].pri_chan &&
  253. sec_chan == n[i].sec_chan) {
  254. match = 1;
  255. break;
  256. }
  257. }
  258. if (!match) {
  259. for (i = 0; n && i < num; i++) {
  260. if (pri_chan == n[i].sec_chan &&
  261. sec_chan == n[i].pri_chan) {
  262. wpa_printf(MSG_INFO, "Switch own primary and "
  263. "secondary channel due to BSS "
  264. "overlap with " MACSTR,
  265. MAC2STR(n[i].bssid));
  266. ieee80211n_switch_pri_sec(iface);
  267. break;
  268. }
  269. }
  270. }
  271. return 1;
  272. }
  273. static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface)
  274. {
  275. int pri_freq, sec_freq;
  276. int affected_start, affected_end;
  277. const struct hostapd_neighbor_bss *n;
  278. size_t i, num;
  279. pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
  280. if (iface->conf->secondary_channel > 0)
  281. sec_freq = pri_freq + 20;
  282. else
  283. sec_freq = pri_freq - 20;
  284. affected_start = (pri_freq + sec_freq) / 2 - 25;
  285. affected_end = (pri_freq + sec_freq) / 2 + 25;
  286. wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
  287. affected_start, affected_end);
  288. n = hostapd_driver_get_neighbor_bss(iface->bss[0], &num);
  289. for (i = 0; n && i < num; i++) {
  290. int pri = n[i].freq;
  291. int sec = pri;
  292. if (n[i].sec_chan) {
  293. if (n[i].sec_chan < n[i].pri_chan)
  294. sec = pri - 20;
  295. else
  296. sec = pri + 20;
  297. }
  298. if ((pri < affected_start || pri > affected_end) &&
  299. (sec < affected_start || sec > affected_end))
  300. continue; /* not within affected channel range */
  301. if (n[i].sec_chan) {
  302. if (pri_freq != pri || sec_freq != sec) {
  303. wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
  304. "mismatch with BSS " MACSTR
  305. " <%d,%d> (chan=%d%c) vs. <%d,%d>",
  306. MAC2STR(n[i].bssid),
  307. pri, sec, n[i].pri_chan,
  308. sec > pri ? '+' : '-',
  309. pri_freq, sec_freq);
  310. return 0;
  311. }
  312. }
  313. /* TODO: 40 MHz intolerant */
  314. }
  315. return 1;
  316. }
  317. static void ieee80211n_check_40mhz(struct hostapd_iface *iface)
  318. {
  319. int oper40;
  320. if (!iface->conf->secondary_channel)
  321. return; /* HT40 not used */
  322. /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
  323. * allowed per IEEE 802.11n/D7.0, 11.14.3.2 */
  324. if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
  325. oper40 = ieee80211n_check_40mhz_5g(iface);
  326. else
  327. oper40 = ieee80211n_check_40mhz_2g4(iface);
  328. if (!oper40) {
  329. wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
  330. "channel pri=%d sec=%d based on overlapping BSSes",
  331. iface->conf->channel,
  332. iface->conf->channel +
  333. iface->conf->secondary_channel * 4);
  334. iface->conf->secondary_channel = 0;
  335. iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  336. }
  337. }
  338. static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
  339. {
  340. u16 hw = iface->current_mode->ht_capab;
  341. u16 conf = iface->conf->ht_capab;
  342. if (!iface->conf->ieee80211n)
  343. return 1;
  344. if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
  345. !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
  346. wpa_printf(MSG_ERROR, "Driver does not support configured "
  347. "HT capability [LDPC]");
  348. return 0;
  349. }
  350. if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
  351. !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
  352. wpa_printf(MSG_ERROR, "Driver does not support configured "
  353. "HT capability [HT40*]");
  354. return 0;
  355. }
  356. if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) &&
  357. (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) {
  358. wpa_printf(MSG_ERROR, "Driver does not support configured "
  359. "HT capability [SMPS-*]");
  360. return 0;
  361. }
  362. if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
  363. !(hw & HT_CAP_INFO_GREEN_FIELD)) {
  364. wpa_printf(MSG_ERROR, "Driver does not support configured "
  365. "HT capability [GF]");
  366. return 0;
  367. }
  368. if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
  369. !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
  370. wpa_printf(MSG_ERROR, "Driver does not support configured "
  371. "HT capability [SHORT-GI-20]");
  372. return 0;
  373. }
  374. if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
  375. !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
  376. wpa_printf(MSG_ERROR, "Driver does not support configured "
  377. "HT capability [SHORT-GI-40]");
  378. return 0;
  379. }
  380. if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
  381. wpa_printf(MSG_ERROR, "Driver does not support configured "
  382. "HT capability [TX-STBC]");
  383. return 0;
  384. }
  385. if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
  386. (hw & HT_CAP_INFO_RX_STBC_MASK)) {
  387. wpa_printf(MSG_ERROR, "Driver does not support configured "
  388. "HT capability [RX-STBC*]");
  389. return 0;
  390. }
  391. if ((conf & HT_CAP_INFO_DELAYED_BA) &&
  392. !(hw & HT_CAP_INFO_DELAYED_BA)) {
  393. wpa_printf(MSG_ERROR, "Driver does not support configured "
  394. "HT capability [DELAYED-BA]");
  395. return 0;
  396. }
  397. if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
  398. !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
  399. wpa_printf(MSG_ERROR, "Driver does not support configured "
  400. "HT capability [MAX-AMSDU-7935]");
  401. return 0;
  402. }
  403. if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
  404. !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
  405. wpa_printf(MSG_ERROR, "Driver does not support configured "
  406. "HT capability [DSSS_CCK-40]");
  407. return 0;
  408. }
  409. if ((conf & HT_CAP_INFO_PSMP_SUPP) && !(hw & HT_CAP_INFO_PSMP_SUPP)) {
  410. wpa_printf(MSG_ERROR, "Driver does not support configured "
  411. "HT capability [PSMP]");
  412. return 0;
  413. }
  414. if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
  415. !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
  416. wpa_printf(MSG_ERROR, "Driver does not support configured "
  417. "HT capability [LSIG-TXOP-PROT]");
  418. return 0;
  419. }
  420. return 1;
  421. }
  422. #endif /* CONFIG_IEEE80211N */
  423. /**
  424. * hostapd_select_hw_mode - Select the hardware mode
  425. * @iface: Pointer to interface data.
  426. * Returns: 0 on success, -1 on failure
  427. *
  428. * Sets up the hardware mode, channel, rates, and passive scanning
  429. * based on the configuration.
  430. */
  431. int hostapd_select_hw_mode(struct hostapd_iface *iface)
  432. {
  433. int i, j, ok, ret;
  434. if (iface->num_hw_features < 1)
  435. return -1;
  436. iface->current_mode = NULL;
  437. for (i = 0; i < iface->num_hw_features; i++) {
  438. struct hostapd_hw_modes *mode = &iface->hw_features[i];
  439. if (mode->mode == iface->conf->hw_mode) {
  440. iface->current_mode = mode;
  441. break;
  442. }
  443. }
  444. if (iface->current_mode == NULL) {
  445. wpa_printf(MSG_ERROR, "Hardware does not support configured "
  446. "mode");
  447. hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
  448. HOSTAPD_LEVEL_WARNING,
  449. "Hardware does not support configured mode "
  450. "(%d)", (int) iface->conf->hw_mode);
  451. return -1;
  452. }
  453. ok = 0;
  454. for (j = 0; j < iface->current_mode->num_channels; j++) {
  455. struct hostapd_channel_data *chan =
  456. &iface->current_mode->channels[j];
  457. if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
  458. (chan->chan == iface->conf->channel)) {
  459. ok = 1;
  460. break;
  461. }
  462. }
  463. if (ok == 0 && iface->conf->channel != 0) {
  464. hostapd_logger(iface->bss[0], NULL,
  465. HOSTAPD_MODULE_IEEE80211,
  466. HOSTAPD_LEVEL_WARNING,
  467. "Configured channel (%d) not found from the "
  468. "channel list of current mode (%d) %s",
  469. iface->conf->channel,
  470. iface->current_mode->mode,
  471. hostapd_hw_mode_txt(iface->current_mode->mode));
  472. iface->current_mode = NULL;
  473. }
  474. if (iface->current_mode == NULL) {
  475. hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
  476. HOSTAPD_LEVEL_WARNING,
  477. "Hardware does not support configured channel");
  478. return -1;
  479. }
  480. #ifdef CONFIG_IEEE80211N
  481. ieee80211n_check_40mhz(iface);
  482. if (!ieee80211n_allowed_ht40_channel_pair(iface))
  483. return -1;
  484. if (!ieee80211n_supported_ht_capab(iface))
  485. return -1;
  486. #endif /* CONFIG_IEEE80211N */
  487. if (hostapd_prepare_rates(iface->bss[0], iface->current_mode)) {
  488. wpa_printf(MSG_ERROR, "Failed to prepare rates table.");
  489. hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
  490. HOSTAPD_LEVEL_WARNING,
  491. "Failed to prepare rates table.");
  492. return -1;
  493. }
  494. ret = hostapd_passive_scan(iface->bss[0], 0,
  495. iface->conf->passive_scan_mode,
  496. iface->conf->passive_scan_interval,
  497. iface->conf->passive_scan_listen,
  498. NULL, NULL);
  499. if (ret) {
  500. if (ret == -1) {
  501. wpa_printf(MSG_DEBUG, "Passive scanning not "
  502. "supported");
  503. } else {
  504. wpa_printf(MSG_ERROR, "Could not set passive "
  505. "scanning: %s", strerror(ret));
  506. }
  507. ret = 0;
  508. }
  509. return ret;
  510. }
  511. const char * hostapd_hw_mode_txt(int mode)
  512. {
  513. switch (mode) {
  514. case HOSTAPD_MODE_IEEE80211A:
  515. return "IEEE 802.11a";
  516. case HOSTAPD_MODE_IEEE80211B:
  517. return "IEEE 802.11b";
  518. case HOSTAPD_MODE_IEEE80211G:
  519. return "IEEE 802.11g";
  520. default:
  521. return "UNKNOWN";
  522. }
  523. }
  524. int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
  525. {
  526. int i;
  527. if (!hapd->iface->current_mode)
  528. return 0;
  529. for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
  530. struct hostapd_channel_data *ch =
  531. &hapd->iface->current_mode->channels[i];
  532. if (ch->chan == chan)
  533. return ch->freq;
  534. }
  535. return 0;
  536. }
  537. int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
  538. {
  539. int i;
  540. if (!hapd->iface->current_mode)
  541. return 0;
  542. for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
  543. struct hostapd_channel_data *ch =
  544. &hapd->iface->current_mode->channels[i];
  545. if (ch->freq == freq)
  546. return ch->chan;
  547. }
  548. return 0;
  549. }