iwl-agn-rxon.c 19 KB

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