iwl-agn-rxon.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include "iwl-dev.h"
  27. #include "iwl-agn.h"
  28. #include "iwl-sta.h"
  29. #include "iwl-core.h"
  30. #include "iwl-agn-calib.h"
  31. #include "iwl-helpers.h"
  32. static int iwlagn_disable_bss(struct iwl_priv *priv,
  33. struct iwl_rxon_context *ctx,
  34. struct iwl_rxon_cmd *send)
  35. {
  36. __le32 old_filter = send->filter_flags;
  37. int ret;
  38. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  39. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
  40. send->filter_flags = old_filter;
  41. if (ret)
  42. IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
  43. return ret;
  44. }
  45. static int iwlagn_disable_pan(struct iwl_priv *priv,
  46. struct iwl_rxon_context *ctx,
  47. struct iwl_rxon_cmd *send)
  48. {
  49. struct iwl_notification_wait disable_wait;
  50. __le32 old_filter = send->filter_flags;
  51. u8 old_dev_type = send->dev_type;
  52. int ret;
  53. iwlagn_init_notification_wait(priv, &disable_wait,
  54. REPLY_WIPAN_DEACTIVATION_COMPLETE,
  55. NULL, NULL);
  56. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  57. send->dev_type = RXON_DEV_TYPE_P2P;
  58. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
  59. send->filter_flags = old_filter;
  60. send->dev_type = old_dev_type;
  61. if (ret) {
  62. IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
  63. iwlagn_remove_notification(priv, &disable_wait);
  64. } else {
  65. ret = iwlagn_wait_notification(priv, &disable_wait, HZ);
  66. if (ret)
  67. IWL_ERR(priv, "Timed out waiting for PAN disable\n");
  68. }
  69. return ret;
  70. }
  71. static void iwlagn_update_qos(struct iwl_priv *priv,
  72. struct iwl_rxon_context *ctx)
  73. {
  74. int ret;
  75. if (!ctx->is_active)
  76. return;
  77. ctx->qos_data.def_qos_parm.qos_flags = 0;
  78. if (ctx->qos_data.qos_active)
  79. ctx->qos_data.def_qos_parm.qos_flags |=
  80. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  81. if (ctx->ht.enabled)
  82. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  83. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  84. ctx->qos_data.qos_active,
  85. ctx->qos_data.def_qos_parm.qos_flags);
  86. ret = iwl_send_cmd_pdu(priv, ctx->qos_cmd,
  87. sizeof(struct iwl_qosparam_cmd),
  88. &ctx->qos_data.def_qos_parm);
  89. if (ret)
  90. IWL_ERR(priv, "Failed to update QoS\n");
  91. }
  92. static int iwlagn_update_beacon(struct iwl_priv *priv,
  93. struct ieee80211_vif *vif)
  94. {
  95. lockdep_assert_held(&priv->mutex);
  96. dev_kfree_skb(priv->beacon_skb);
  97. priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
  98. if (!priv->beacon_skb)
  99. return -ENOMEM;
  100. return iwlagn_send_beacon_cmd(priv);
  101. }
  102. static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
  103. struct iwl_rxon_context *ctx)
  104. {
  105. int ret = 0;
  106. struct iwl_rxon_assoc_cmd rxon_assoc;
  107. const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
  108. const struct iwl_rxon_cmd *rxon2 = &ctx->active;
  109. if ((rxon1->flags == rxon2->flags) &&
  110. (rxon1->filter_flags == rxon2->filter_flags) &&
  111. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  112. (rxon1->ofdm_ht_single_stream_basic_rates ==
  113. rxon2->ofdm_ht_single_stream_basic_rates) &&
  114. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  115. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  116. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  117. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  118. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  119. (rxon1->rx_chain == rxon2->rx_chain) &&
  120. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  121. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  122. return 0;
  123. }
  124. rxon_assoc.flags = ctx->staging.flags;
  125. rxon_assoc.filter_flags = ctx->staging.filter_flags;
  126. rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
  127. rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
  128. rxon_assoc.reserved1 = 0;
  129. rxon_assoc.reserved2 = 0;
  130. rxon_assoc.reserved3 = 0;
  131. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  132. ctx->staging.ofdm_ht_single_stream_basic_rates;
  133. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  134. ctx->staging.ofdm_ht_dual_stream_basic_rates;
  135. rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
  136. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  137. ctx->staging.ofdm_ht_triple_stream_basic_rates;
  138. rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
  139. ret = iwl_send_cmd_pdu_async(priv, ctx->rxon_assoc_cmd,
  140. sizeof(rxon_assoc), &rxon_assoc, NULL);
  141. if (ret)
  142. return ret;
  143. return ret;
  144. }
  145. static int iwlagn_rxon_disconn(struct iwl_priv *priv,
  146. struct iwl_rxon_context *ctx)
  147. {
  148. int ret;
  149. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  150. if (ctx->ctxid == IWL_RXON_CTX_BSS)
  151. ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
  152. else
  153. ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
  154. if (ret)
  155. return ret;
  156. /*
  157. * Un-assoc RXON clears the station table and WEP
  158. * keys, so we have to restore those afterwards.
  159. */
  160. iwl_clear_ucode_stations(priv, ctx);
  161. iwl_restore_stations(priv, ctx);
  162. ret = iwl_restore_default_wep_keys(priv, ctx);
  163. if (ret) {
  164. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  165. return ret;
  166. }
  167. memcpy(active, &ctx->staging, sizeof(*active));
  168. return 0;
  169. }
  170. static int iwlagn_rxon_connect(struct iwl_priv *priv,
  171. struct iwl_rxon_context *ctx)
  172. {
  173. int ret;
  174. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  175. /* RXON timing must be before associated RXON */
  176. ret = iwl_send_rxon_timing(priv, ctx);
  177. if (ret) {
  178. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  179. return ret;
  180. }
  181. /* QoS info may be cleared by previous un-assoc RXON */
  182. iwlagn_update_qos(priv, ctx);
  183. /*
  184. * We'll run into this code path when beaconing is
  185. * enabled, but then we also need to send the beacon
  186. * to the device.
  187. */
  188. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
  189. ret = iwlagn_update_beacon(priv, ctx->vif);
  190. if (ret) {
  191. IWL_ERR(priv,
  192. "Error sending required beacon (%d)!\n",
  193. ret);
  194. return ret;
  195. }
  196. }
  197. priv->start_calib = 0;
  198. /*
  199. * Apply the new configuration.
  200. *
  201. * Associated RXON doesn't clear the station table in uCode,
  202. * so we don't need to restore stations etc. after this.
  203. */
  204. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
  205. sizeof(struct iwl_rxon_cmd), &ctx->staging);
  206. if (ret) {
  207. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  208. return ret;
  209. }
  210. memcpy(active, &ctx->staging, sizeof(*active));
  211. iwl_reprogram_ap_sta(priv, ctx);
  212. /* IBSS beacon needs to be sent after setting assoc */
  213. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
  214. if (iwlagn_update_beacon(priv, ctx->vif))
  215. IWL_ERR(priv, "Error sending IBSS beacon\n");
  216. iwl_init_sensitivity(priv);
  217. /*
  218. * If we issue a new RXON command which required a tune then
  219. * we must send a new TXPOWER command or we won't be able to
  220. * Tx any frames.
  221. *
  222. * It's expected we set power here if channel is changing.
  223. */
  224. ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
  225. if (ret) {
  226. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  227. return ret;
  228. }
  229. return 0;
  230. }
  231. /**
  232. * iwlagn_commit_rxon - commit staging_rxon to hardware
  233. *
  234. * The RXON command in staging_rxon is committed to the hardware and
  235. * the active_rxon structure is updated with the new data. This
  236. * function correctly transitions out of the RXON_ASSOC_MSK state if
  237. * a HW tune is required based on the RXON structure changes.
  238. *
  239. * The connect/disconnect flow should be as the following:
  240. *
  241. * 1. make sure send RXON command with association bit unset if not connect
  242. * this should include the channel and the band for the candidate
  243. * to be connected to
  244. * 2. Add Station before RXON association with the AP
  245. * 3. RXON_timing has to send before RXON for connection
  246. * 4. full RXON command - associated bit set
  247. * 5. use RXON_ASSOC command to update any flags changes
  248. */
  249. int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  250. {
  251. /* cast away the const for active_rxon in this function */
  252. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  253. bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  254. bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
  255. int ret;
  256. lockdep_assert_held(&priv->mutex);
  257. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  258. return -EINVAL;
  259. if (!iwl_is_alive(priv))
  260. return -EBUSY;
  261. /* This function hardcodes a bunch of dual-mode assumptions */
  262. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  263. if (!ctx->is_active)
  264. return 0;
  265. /* always get timestamp with Rx frame */
  266. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  267. if (ctx->ctxid == IWL_RXON_CTX_PAN && priv->_agn.hw_roc_channel) {
  268. struct ieee80211_channel *chan = priv->_agn.hw_roc_channel;
  269. iwl_set_rxon_channel(priv, chan, ctx);
  270. iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
  271. ctx->staging.filter_flags |=
  272. RXON_FILTER_ASSOC_MSK |
  273. RXON_FILTER_PROMISC_MSK |
  274. RXON_FILTER_CTL2HOST_MSK;
  275. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  276. new_assoc = true;
  277. if (memcmp(&ctx->staging, &ctx->active,
  278. sizeof(ctx->staging)) == 0)
  279. return 0;
  280. }
  281. if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
  282. !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
  283. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  284. else
  285. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  286. iwl_print_rx_config_cmd(priv, ctx);
  287. ret = iwl_check_rxon_cmd(priv, ctx);
  288. if (ret) {
  289. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  290. return -EINVAL;
  291. }
  292. /*
  293. * receive commit_rxon request
  294. * abort any previous channel switch if still in process
  295. */
  296. if (priv->switch_rxon.switch_in_progress &&
  297. (priv->switch_rxon.channel != ctx->staging.channel)) {
  298. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  299. le16_to_cpu(priv->switch_rxon.channel));
  300. iwl_chswitch_done(priv, false);
  301. }
  302. /*
  303. * If we don't need to send a full RXON, we can use
  304. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  305. * and other flags for the current radio configuration.
  306. */
  307. if (!iwl_full_rxon_required(priv, ctx)) {
  308. ret = iwlagn_send_rxon_assoc(priv, ctx);
  309. if (ret) {
  310. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  311. return ret;
  312. }
  313. memcpy(active, &ctx->staging, sizeof(*active));
  314. return 0;
  315. }
  316. if (priv->cfg->ops->hcmd->set_pan_params) {
  317. ret = priv->cfg->ops->hcmd->set_pan_params(priv);
  318. if (ret)
  319. return ret;
  320. }
  321. iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
  322. IWL_DEBUG_INFO(priv,
  323. "Going to commit RXON\n"
  324. " * with%s RXON_FILTER_ASSOC_MSK\n"
  325. " * channel = %d\n"
  326. " * bssid = %pM\n",
  327. (new_assoc ? "" : "out"),
  328. le16_to_cpu(ctx->staging.channel),
  329. ctx->staging.bssid_addr);
  330. /*
  331. * Always clear associated first, but with the correct config.
  332. * This is required as for example station addition for the
  333. * AP station must be done after the BSSID is set to correctly
  334. * set up filters in the device.
  335. */
  336. ret = iwlagn_rxon_disconn(priv, ctx);
  337. if (ret)
  338. return ret;
  339. if (new_assoc)
  340. return iwlagn_rxon_connect(priv, ctx);
  341. return 0;
  342. }
  343. int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
  344. {
  345. struct iwl_priv *priv = hw->priv;
  346. struct iwl_rxon_context *ctx;
  347. struct ieee80211_conf *conf = &hw->conf;
  348. struct ieee80211_channel *channel = conf->channel;
  349. const struct iwl_channel_info *ch_info;
  350. int ret = 0;
  351. IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
  352. mutex_lock(&priv->mutex);
  353. if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
  354. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  355. goto out;
  356. }
  357. if (!iwl_is_ready(priv)) {
  358. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  359. goto out;
  360. }
  361. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  362. IEEE80211_CONF_CHANGE_CHANNEL)) {
  363. /* mac80211 uses static for non-HT which is what we want */
  364. priv->current_ht_config.smps = conf->smps_mode;
  365. /*
  366. * Recalculate chain counts.
  367. *
  368. * If monitor mode is enabled then mac80211 will
  369. * set up the SM PS mode to OFF if an HT channel is
  370. * configured.
  371. */
  372. if (priv->cfg->ops->hcmd->set_rxon_chain)
  373. for_each_context(priv, ctx)
  374. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  375. }
  376. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  377. unsigned long flags;
  378. ch_info = iwl_get_channel_info(priv, channel->band,
  379. channel->hw_value);
  380. if (!is_channel_valid(ch_info)) {
  381. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  382. ret = -EINVAL;
  383. goto out;
  384. }
  385. spin_lock_irqsave(&priv->lock, flags);
  386. for_each_context(priv, ctx) {
  387. /* Configure HT40 channels */
  388. if (ctx->ht.enabled != conf_is_ht(conf))
  389. ctx->ht.enabled = conf_is_ht(conf);
  390. if (ctx->ht.enabled) {
  391. if (conf_is_ht40_minus(conf)) {
  392. ctx->ht.extension_chan_offset =
  393. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  394. ctx->ht.is_40mhz = true;
  395. } else if (conf_is_ht40_plus(conf)) {
  396. ctx->ht.extension_chan_offset =
  397. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  398. ctx->ht.is_40mhz = true;
  399. } else {
  400. ctx->ht.extension_chan_offset =
  401. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  402. ctx->ht.is_40mhz = false;
  403. }
  404. } else
  405. ctx->ht.is_40mhz = false;
  406. /*
  407. * Default to no protection. Protection mode will
  408. * later be set from BSS config in iwl_ht_conf
  409. */
  410. ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  411. /* if we are switching from ht to 2.4 clear flags
  412. * from any ht related info since 2.4 does not
  413. * support ht */
  414. if (le16_to_cpu(ctx->staging.channel) !=
  415. channel->hw_value)
  416. ctx->staging.flags = 0;
  417. iwl_set_rxon_channel(priv, channel, ctx);
  418. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  419. iwl_set_flags_for_band(priv, ctx, channel->band,
  420. ctx->vif);
  421. }
  422. spin_unlock_irqrestore(&priv->lock, flags);
  423. iwl_update_bcast_stations(priv);
  424. /*
  425. * The list of supported rates and rate mask can be different
  426. * for each band; since the band may have changed, reset
  427. * the rate mask to what mac80211 lists.
  428. */
  429. iwl_set_rate(priv);
  430. }
  431. if (changed & (IEEE80211_CONF_CHANGE_PS |
  432. IEEE80211_CONF_CHANGE_IDLE)) {
  433. ret = iwl_power_update_mode(priv, false);
  434. if (ret)
  435. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  436. }
  437. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  438. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  439. priv->tx_power_user_lmt, conf->power_level);
  440. iwl_set_tx_power(priv, conf->power_level, false);
  441. }
  442. for_each_context(priv, ctx) {
  443. if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  444. continue;
  445. iwlagn_commit_rxon(priv, ctx);
  446. }
  447. out:
  448. mutex_unlock(&priv->mutex);
  449. return ret;
  450. }
  451. static void iwlagn_check_needed_chains(struct iwl_priv *priv,
  452. struct iwl_rxon_context *ctx,
  453. struct ieee80211_bss_conf *bss_conf)
  454. {
  455. struct ieee80211_vif *vif = ctx->vif;
  456. struct iwl_rxon_context *tmp;
  457. struct ieee80211_sta *sta;
  458. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  459. struct ieee80211_sta_ht_cap *ht_cap;
  460. bool need_multiple;
  461. lockdep_assert_held(&priv->mutex);
  462. switch (vif->type) {
  463. case NL80211_IFTYPE_STATION:
  464. rcu_read_lock();
  465. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  466. if (!sta) {
  467. /*
  468. * If at all, this can only happen through a race
  469. * when the AP disconnects us while we're still
  470. * setting up the connection, in that case mac80211
  471. * will soon tell us about that.
  472. */
  473. need_multiple = false;
  474. rcu_read_unlock();
  475. break;
  476. }
  477. ht_cap = &sta->ht_cap;
  478. need_multiple = true;
  479. /*
  480. * If the peer advertises no support for receiving 2 and 3
  481. * stream MCS rates, it can't be transmitting them either.
  482. */
  483. if (ht_cap->mcs.rx_mask[1] == 0 &&
  484. ht_cap->mcs.rx_mask[2] == 0) {
  485. need_multiple = false;
  486. } else if (!(ht_cap->mcs.tx_params &
  487. IEEE80211_HT_MCS_TX_DEFINED)) {
  488. /* If it can't TX MCS at all ... */
  489. need_multiple = false;
  490. } else if (ht_cap->mcs.tx_params &
  491. IEEE80211_HT_MCS_TX_RX_DIFF) {
  492. int maxstreams;
  493. /*
  494. * But if it can receive them, it might still not
  495. * be able to transmit them, which is what we need
  496. * to check here -- so check the number of streams
  497. * it advertises for TX (if different from RX).
  498. */
  499. maxstreams = (ht_cap->mcs.tx_params &
  500. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
  501. maxstreams >>=
  502. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  503. maxstreams += 1;
  504. if (maxstreams <= 1)
  505. need_multiple = false;
  506. }
  507. rcu_read_unlock();
  508. break;
  509. case NL80211_IFTYPE_ADHOC:
  510. /* currently */
  511. need_multiple = false;
  512. break;
  513. default:
  514. /* only AP really */
  515. need_multiple = true;
  516. break;
  517. }
  518. ctx->ht_need_multiple_chains = need_multiple;
  519. if (!need_multiple) {
  520. /* check all contexts */
  521. for_each_context(priv, tmp) {
  522. if (!tmp->vif)
  523. continue;
  524. if (tmp->ht_need_multiple_chains) {
  525. need_multiple = true;
  526. break;
  527. }
  528. }
  529. }
  530. ht_conf->single_chain_sufficient = !need_multiple;
  531. }
  532. void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
  533. struct ieee80211_vif *vif,
  534. struct ieee80211_bss_conf *bss_conf,
  535. u32 changes)
  536. {
  537. struct iwl_priv *priv = hw->priv;
  538. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  539. int ret;
  540. bool force = false;
  541. mutex_lock(&priv->mutex);
  542. if (unlikely(!iwl_is_ready(priv))) {
  543. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  544. mutex_unlock(&priv->mutex);
  545. return;
  546. }
  547. if (unlikely(!ctx->vif)) {
  548. IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
  549. mutex_unlock(&priv->mutex);
  550. return;
  551. }
  552. if (changes & BSS_CHANGED_BEACON_INT)
  553. force = true;
  554. if (changes & BSS_CHANGED_QOS) {
  555. ctx->qos_data.qos_active = bss_conf->qos;
  556. iwlagn_update_qos(priv, ctx);
  557. }
  558. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  559. if (vif->bss_conf.use_short_preamble)
  560. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  561. else
  562. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  563. if (changes & BSS_CHANGED_ASSOC) {
  564. if (bss_conf->assoc) {
  565. priv->timestamp = bss_conf->timestamp;
  566. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  567. } else {
  568. /*
  569. * If we disassociate while there are pending
  570. * frames, just wake up the queues and let the
  571. * frames "escape" ... This shouldn't really
  572. * be happening to start with, but we should
  573. * not get stuck in this case either since it
  574. * can happen if userspace gets confused.
  575. */
  576. if (ctx->last_tx_rejected) {
  577. ctx->last_tx_rejected = false;
  578. iwl_wake_any_queue(priv, ctx);
  579. }
  580. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  581. }
  582. }
  583. if (ctx->ht.enabled) {
  584. ctx->ht.protection = bss_conf->ht_operation_mode &
  585. IEEE80211_HT_OP_MODE_PROTECTION;
  586. ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
  587. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  588. iwlagn_check_needed_chains(priv, ctx, bss_conf);
  589. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  590. }
  591. if (priv->cfg->ops->hcmd->set_rxon_chain)
  592. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  593. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  594. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  595. else
  596. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  597. if (bss_conf->use_cts_prot)
  598. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  599. else
  600. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  601. memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
  602. if (vif->type == NL80211_IFTYPE_AP ||
  603. vif->type == NL80211_IFTYPE_ADHOC) {
  604. if (vif->bss_conf.enable_beacon) {
  605. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  606. priv->beacon_ctx = ctx;
  607. } else {
  608. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  609. priv->beacon_ctx = NULL;
  610. }
  611. }
  612. if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  613. iwlagn_commit_rxon(priv, ctx);
  614. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
  615. /*
  616. * The chain noise calibration will enable PM upon
  617. * completion. If calibration has already been run
  618. * then we need to enable power management here.
  619. */
  620. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  621. iwl_power_update_mode(priv, false);
  622. /* Enable RX differential gain and sensitivity calibrations */
  623. iwl_chain_noise_reset(priv);
  624. priv->start_calib = 1;
  625. }
  626. if (changes & BSS_CHANGED_IBSS) {
  627. ret = iwlagn_manage_ibss_station(priv, vif,
  628. bss_conf->ibss_joined);
  629. if (ret)
  630. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  631. bss_conf->ibss_joined ? "add" : "remove",
  632. bss_conf->bssid);
  633. }
  634. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
  635. priv->beacon_ctx) {
  636. if (iwlagn_update_beacon(priv, vif))
  637. IWL_ERR(priv, "Error sending IBSS beacon\n");
  638. }
  639. mutex_unlock(&priv->mutex);
  640. }
  641. void iwlagn_post_scan(struct iwl_priv *priv)
  642. {
  643. struct iwl_rxon_context *ctx;
  644. /*
  645. * Since setting the RXON may have been deferred while
  646. * performing the scan, fire one off if needed
  647. */
  648. for_each_context(priv, ctx)
  649. if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  650. iwlagn_commit_rxon(priv, ctx);
  651. if (priv->cfg->ops->hcmd->set_pan_params)
  652. priv->cfg->ops->hcmd->set_pan_params(priv);
  653. }