iwl-agn-rxon.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. __le32 old_filter = send->filter_flags;
  49. u8 old_dev_type = send->dev_type;
  50. int ret;
  51. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  52. send->dev_type = RXON_DEV_TYPE_P2P;
  53. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
  54. send->filter_flags = old_filter;
  55. send->dev_type = old_dev_type;
  56. if (ret)
  57. IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
  58. /* FIXME: WAIT FOR PAN DISABLE */
  59. msleep(300);
  60. return ret;
  61. }
  62. /**
  63. * iwlagn_commit_rxon - commit staging_rxon to hardware
  64. *
  65. * The RXON command in staging_rxon is committed to the hardware and
  66. * the active_rxon structure is updated with the new data. This
  67. * function correctly transitions out of the RXON_ASSOC_MSK state if
  68. * a HW tune is required based on the RXON structure changes.
  69. */
  70. int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  71. {
  72. /* cast away the const for active_rxon in this function */
  73. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  74. bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
  75. bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  76. int ret;
  77. lockdep_assert_held(&priv->mutex);
  78. if (!iwl_is_alive(priv))
  79. return -EBUSY;
  80. /* This function hardcodes a bunch of dual-mode assumptions */
  81. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  82. if (!ctx->is_active)
  83. return 0;
  84. /* always get timestamp with Rx frame */
  85. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  86. if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
  87. !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
  88. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  89. else
  90. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  91. ret = iwl_check_rxon_cmd(priv, ctx);
  92. if (ret) {
  93. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  94. return -EINVAL;
  95. }
  96. /*
  97. * receive commit_rxon request
  98. * abort any previous channel switch if still in process
  99. */
  100. if (priv->switch_rxon.switch_in_progress &&
  101. (priv->switch_rxon.channel != ctx->staging.channel)) {
  102. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  103. le16_to_cpu(priv->switch_rxon.channel));
  104. iwl_chswitch_done(priv, false);
  105. }
  106. /*
  107. * If we don't need to send a full RXON, we can use
  108. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  109. * and other flags for the current radio configuration.
  110. */
  111. if (!iwl_full_rxon_required(priv, ctx)) {
  112. ret = iwl_send_rxon_assoc(priv, ctx);
  113. if (ret) {
  114. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  115. return ret;
  116. }
  117. memcpy(active, &ctx->staging, sizeof(*active));
  118. iwl_print_rx_config_cmd(priv, ctx);
  119. return 0;
  120. }
  121. if (priv->cfg->ops->hcmd->set_pan_params) {
  122. ret = priv->cfg->ops->hcmd->set_pan_params(priv);
  123. if (ret)
  124. return ret;
  125. }
  126. iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
  127. IWL_DEBUG_INFO(priv,
  128. "Going to commit RXON\n"
  129. " * with%s RXON_FILTER_ASSOC_MSK\n"
  130. " * channel = %d\n"
  131. " * bssid = %pM\n",
  132. (new_assoc ? "" : "out"),
  133. le16_to_cpu(ctx->staging.channel),
  134. ctx->staging.bssid_addr);
  135. /*
  136. * If we are currently associated and the new config is also
  137. * going to be associated, OR if the new config is simply not
  138. * associated, clear associated.
  139. */
  140. if ((old_assoc && new_assoc) || !new_assoc) {
  141. struct iwl_rxon_cmd *send = active;
  142. if (!new_assoc)
  143. send = &ctx->staging;
  144. if (ctx->ctxid == IWL_RXON_CTX_BSS)
  145. ret = iwlagn_disable_bss(priv, ctx, send);
  146. else
  147. ret = iwlagn_disable_pan(priv, ctx, send);
  148. if (ret)
  149. return ret;
  150. if (send != active)
  151. memcpy(active, send, sizeof(*active));
  152. /*
  153. * Un-assoc RXON clears the station table and WEP
  154. * keys, so we have to restore those afterwards.
  155. */
  156. iwl_clear_ucode_stations(priv, ctx);
  157. iwl_restore_stations(priv, ctx);
  158. ret = iwl_restore_default_wep_keys(priv, ctx);
  159. if (ret) {
  160. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  161. return ret;
  162. }
  163. }
  164. /* RXON timing must be before associated RXON */
  165. ret = iwl_send_rxon_timing(priv, ctx);
  166. if (ret) {
  167. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  168. return ret;
  169. }
  170. if (new_assoc) {
  171. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP ||
  172. ctx->vif->type == NL80211_IFTYPE_ADHOC)) {
  173. /*
  174. * We'll run into this code path when beaconing is
  175. * enabled, but then we also need to send the beacon
  176. * to the device.
  177. */
  178. dev_kfree_skb(priv->beacon_skb);
  179. priv->beacon_skb = ieee80211_beacon_get(priv->hw,
  180. ctx->vif);
  181. iwlagn_send_beacon_cmd(priv);
  182. }
  183. priv->start_calib = 0;
  184. /*
  185. * Apply the new configuration.
  186. *
  187. * Associated RXON doesn't clear the station table in uCode,
  188. * so we don't need to restore stations etc. after this.
  189. */
  190. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
  191. sizeof(struct iwl_rxon_cmd), &ctx->staging);
  192. if (ret) {
  193. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  194. return ret;
  195. }
  196. memcpy(active, &ctx->staging, sizeof(*active));
  197. }
  198. iwl_print_rx_config_cmd(priv, ctx);
  199. iwl_init_sensitivity(priv);
  200. /*
  201. * If we issue a new RXON command which required a tune then we must
  202. * send a new TXPOWER command or we won't be able to Tx any frames.
  203. *
  204. * FIXME: which RXON requires a tune? Can we optimise this out in
  205. * some cases?
  206. */
  207. ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
  208. if (ret) {
  209. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  210. return ret;
  211. }
  212. return 0;
  213. }
  214. int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
  215. {
  216. struct iwl_priv *priv = hw->priv;
  217. struct iwl_rxon_context *ctx;
  218. struct ieee80211_conf *conf = &hw->conf;
  219. struct ieee80211_channel *channel = conf->channel;
  220. const struct iwl_channel_info *ch_info;
  221. int ret = 0;
  222. IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
  223. mutex_lock(&priv->mutex);
  224. if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
  225. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  226. goto out;
  227. }
  228. if (!iwl_is_ready(priv)) {
  229. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  230. goto out;
  231. }
  232. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  233. IEEE80211_CONF_CHANGE_CHANNEL)) {
  234. /* mac80211 uses static for non-HT which is what we want */
  235. priv->current_ht_config.smps = conf->smps_mode;
  236. /*
  237. * Recalculate chain counts.
  238. *
  239. * If monitor mode is enabled then mac80211 will
  240. * set up the SM PS mode to OFF if an HT channel is
  241. * configured.
  242. */
  243. if (priv->cfg->ops->hcmd->set_rxon_chain)
  244. for_each_context(priv, ctx)
  245. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  246. }
  247. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  248. unsigned long flags;
  249. ch_info = iwl_get_channel_info(priv, channel->band,
  250. channel->hw_value);
  251. if (!is_channel_valid(ch_info)) {
  252. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  253. ret = -EINVAL;
  254. goto out;
  255. }
  256. spin_lock_irqsave(&priv->lock, flags);
  257. for_each_context(priv, ctx) {
  258. /* Configure HT40 channels */
  259. ctx->ht.enabled = conf_is_ht(conf);
  260. if (ctx->ht.enabled) {
  261. if (conf_is_ht40_minus(conf)) {
  262. ctx->ht.extension_chan_offset =
  263. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  264. ctx->ht.is_40mhz = true;
  265. } else if (conf_is_ht40_plus(conf)) {
  266. ctx->ht.extension_chan_offset =
  267. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  268. ctx->ht.is_40mhz = true;
  269. } else {
  270. ctx->ht.extension_chan_offset =
  271. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  272. ctx->ht.is_40mhz = false;
  273. }
  274. } else
  275. ctx->ht.is_40mhz = false;
  276. /*
  277. * Default to no protection. Protection mode will
  278. * later be set from BSS config in iwl_ht_conf
  279. */
  280. ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  281. /* if we are switching from ht to 2.4 clear flags
  282. * from any ht related info since 2.4 does not
  283. * support ht */
  284. if (le16_to_cpu(ctx->staging.channel) !=
  285. channel->hw_value)
  286. ctx->staging.flags = 0;
  287. iwl_set_rxon_channel(priv, channel, ctx);
  288. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  289. iwl_set_flags_for_band(priv, ctx, channel->band,
  290. ctx->vif);
  291. }
  292. spin_unlock_irqrestore(&priv->lock, flags);
  293. iwl_update_bcast_stations(priv);
  294. /*
  295. * The list of supported rates and rate mask can be different
  296. * for each band; since the band may have changed, reset
  297. * the rate mask to what mac80211 lists.
  298. */
  299. iwl_set_rate(priv);
  300. }
  301. if (changed & (IEEE80211_CONF_CHANGE_PS |
  302. IEEE80211_CONF_CHANGE_IDLE)) {
  303. ret = iwl_power_update_mode(priv, false);
  304. if (ret)
  305. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  306. }
  307. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  308. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  309. priv->tx_power_user_lmt, conf->power_level);
  310. iwl_set_tx_power(priv, conf->power_level, false);
  311. }
  312. for_each_context(priv, ctx) {
  313. if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  314. continue;
  315. iwlagn_commit_rxon(priv, ctx);
  316. }
  317. out:
  318. mutex_unlock(&priv->mutex);
  319. return ret;
  320. }
  321. static void iwlagn_update_qos(struct iwl_priv *priv,
  322. struct iwl_rxon_context *ctx)
  323. {
  324. int ret;
  325. if (!ctx->is_active)
  326. return;
  327. ctx->qos_data.def_qos_parm.qos_flags = 0;
  328. if (ctx->qos_data.qos_active)
  329. ctx->qos_data.def_qos_parm.qos_flags |=
  330. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  331. if (ctx->ht.enabled)
  332. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  333. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  334. ctx->qos_data.qos_active,
  335. ctx->qos_data.def_qos_parm.qos_flags);
  336. ret = iwl_send_cmd_pdu(priv, ctx->qos_cmd,
  337. sizeof(struct iwl_qosparam_cmd),
  338. &ctx->qos_data.def_qos_parm);
  339. if (ret)
  340. IWL_ERR(priv, "Failed to update QoS\n");
  341. }
  342. static void iwlagn_check_needed_chains(struct iwl_priv *priv,
  343. struct iwl_rxon_context *ctx,
  344. struct ieee80211_bss_conf *bss_conf)
  345. {
  346. struct ieee80211_vif *vif = ctx->vif;
  347. struct iwl_rxon_context *tmp;
  348. struct ieee80211_sta *sta;
  349. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  350. bool need_multiple;
  351. lockdep_assert_held(&priv->mutex);
  352. switch (vif->type) {
  353. case NL80211_IFTYPE_STATION:
  354. rcu_read_lock();
  355. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  356. if (sta) {
  357. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  358. int maxstreams;
  359. maxstreams = (ht_cap->mcs.tx_params &
  360. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  361. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  362. maxstreams += 1;
  363. if ((ht_cap->mcs.rx_mask[1] == 0) &&
  364. (ht_cap->mcs.rx_mask[2] == 0))
  365. need_multiple = false;
  366. if (maxstreams <= 1)
  367. need_multiple = true;
  368. } else {
  369. /*
  370. * If at all, this can only happen through a race
  371. * when the AP disconnects us while we're still
  372. * setting up the connection, in that case mac80211
  373. * will soon tell us about that.
  374. */
  375. need_multiple = false;
  376. }
  377. rcu_read_unlock();
  378. break;
  379. case NL80211_IFTYPE_ADHOC:
  380. /* currently */
  381. need_multiple = false;
  382. break;
  383. default:
  384. /* only AP really */
  385. need_multiple = true;
  386. break;
  387. }
  388. ctx->ht_need_multiple_chains = need_multiple;
  389. if (!need_multiple) {
  390. /* check all contexts */
  391. for_each_context(priv, tmp) {
  392. if (!tmp->vif)
  393. continue;
  394. if (tmp->ht_need_multiple_chains) {
  395. need_multiple = true;
  396. break;
  397. }
  398. }
  399. }
  400. ht_conf->single_chain_sufficient = !need_multiple;
  401. }
  402. void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
  403. struct ieee80211_vif *vif,
  404. struct ieee80211_bss_conf *bss_conf,
  405. u32 changes)
  406. {
  407. struct iwl_priv *priv = hw->priv;
  408. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  409. int ret;
  410. bool force = false;
  411. mutex_lock(&priv->mutex);
  412. if (changes & BSS_CHANGED_BEACON_INT)
  413. force = true;
  414. if (changes & BSS_CHANGED_QOS) {
  415. ctx->qos_data.qos_active = bss_conf->qos;
  416. iwlagn_update_qos(priv, ctx);
  417. }
  418. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  419. if (vif->bss_conf.use_short_preamble)
  420. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  421. else
  422. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  423. if (changes & BSS_CHANGED_ASSOC) {
  424. if (bss_conf->assoc) {
  425. iwl_led_associate(priv);
  426. priv->timestamp = bss_conf->timestamp;
  427. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  428. } else {
  429. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  430. iwl_led_disassociate(priv);
  431. }
  432. }
  433. if (ctx->ht.enabled) {
  434. ctx->ht.protection = bss_conf->ht_operation_mode &
  435. IEEE80211_HT_OP_MODE_PROTECTION;
  436. ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
  437. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  438. iwlagn_check_needed_chains(priv, ctx, bss_conf);
  439. }
  440. if (priv->cfg->ops->hcmd->set_rxon_chain)
  441. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  442. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  443. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  444. else
  445. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  446. if (bss_conf->use_cts_prot)
  447. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  448. else
  449. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  450. memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
  451. if (vif->type == NL80211_IFTYPE_AP ||
  452. vif->type == NL80211_IFTYPE_ADHOC) {
  453. if (vif->bss_conf.enable_beacon) {
  454. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  455. priv->beacon_ctx = ctx;
  456. } else {
  457. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  458. priv->beacon_ctx = NULL;
  459. }
  460. }
  461. if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  462. iwlagn_commit_rxon(priv, ctx);
  463. if (changes & BSS_CHANGED_IBSS) {
  464. ret = iwlagn_manage_ibss_station(priv, vif,
  465. bss_conf->ibss_joined);
  466. if (ret)
  467. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  468. bss_conf->ibss_joined ? "add" : "remove",
  469. bss_conf->bssid);
  470. }
  471. mutex_unlock(&priv->mutex);
  472. }