iwl-agn-rxon.c 22 KB

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