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