hw_features.c 21 KB

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