iwl-agn-rxon.c 19 KB

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